Native JSON support in MYSQL 5.7 what are the pros and cons of JSON data type in MYSQL?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction to JSON in MySQL 5.7
With the release of MySQL 5.7, Oracle made a significant step forward by introducing native support for JSON data types, thereby enhancing its capabilities as a document store and bolstering its function beyond traditional relational database paradigms. This upgrade allows developers to gain the flexibility of handling semi-structured data while leveraging MySQL's powerful indexing and querying features.
What is JSON?
JavaScript Object Notation (JSON) is a lightweight data interchange format that's easy for humans to read and write and easy for machines to parse and generate. Its key-value pair structure is similar to Python dictionaries, PHP arrays, or JavaScript objects, making it a versatile format.
JSON Data Type in MySQL 5.7
Storing JSON Data
MySQL 5.7 introduces a JSON
data type that is stored internally as a binary format to facilitate efficient access to data members. This format is adapted to allow quick lookups and manipulation while maintaining JSON’s hierarchical structure.
Example of Creating a Table with JSON Data Type:
- JSON format enables developers to store complex data structures such as nested documents and arrays directly in MySQL tables.
- No need for rigid table schemes to match JSON properties exactly.
- MySQL 5.7 provides a plethora of JSON functions for manipulation and retrieval without extensive parsing, including
JSON_OBJECT(),JSON_ARRAY(),JSON_INSERT(),JSON_REPLACE(),JSON_REMOVE(), and more. - Example:
SELECT JSON_UNQUOTE(JSON_EXTRACT(profile, '$.email')) FROM user_profiles WHERE id=1; - The ability to create indexes on JSON values using generated columns to optimize queries.
- Example:
- JSON values are automatically validated when inserted, preventing malformed data.
- Although JSON data types are generally fast, complex queries can suffer performance hits compared to normalized tables with proper schemas.
- Full-text search isn't natively supported within JSON columns. Developers may need workarounds that introduce complexity.
- Binary representation can lead to increased storage use compared to optimized relational databases, particularly for large datasets with simple structure.
- Moving JSON data into a more normalized structure can become labor-intensive, particularly if designed poorly.

