Skip to the content.

Don’t Use JSON Columns in MySQL Here’s Why

TLDR: Storing data in JSON fields may seem convenient, but it introduces significant limitations in terms of query performance, validation, and data structure enforcement. Traditional columns offer better optimization, validation, and scalability.

Storing data in separate columns takes advantage of the features that relational databases offer. Using individual columns enables efficient aggregation and filtering without the overhead of parsing non-relational structures, which often requires third-party tools or custom functions.

JSON data lacks a fixed structure, making consistency checks impossible without parsing and writing custom validations. Though storing variable or complex structures is easier, it introduces several issues.

Drawbacks of Storing Data in JSON Fields

The database server struggles to:

What Is Gained?

General Guideline

Use traditional columns whenever possible, especially if performing calculations on parts of the data. MySQL, with well-designed indexes, can manage hundreds of millions of rows efficiently. Problems generally arise when tables exceed one billion rows.

When to Use JSON

JSON is suitable when consistency enforcement isn’t critical, or when the data is not used for statistical queries or filtering. However, even in these cases, the assumption of never needing such functionality often proves false. JSON can be advantageous when dealing with rarely changed information or applications that expect JSON, optimizing for read and load performance.

NOTE: For further reading visit: How to Work with JSON Data in MySQL and Get JSON from table with PHP PDO.

Ref: Code Axion The Security Breach - Medium