MariaDB JSON Data Type: LONGTEXT Alias and Validation
MariaDB’s JSON data type is an alias for LONGTEXT COLLATE utf8mb4_bin, not MySQL’s binary JSON storage format. MariaDB uses the alias for compatibility with MySQL JSON columns and dumps. See the official MariaDB JSON data type reference.
Create a JSON column
CREATE TABLE events (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
payload JSON,
PRIMARY KEY (id)
);
In MariaDB 10.4.3 and later, the JSON alias automatically adds a CHECK (JSON_VALID(payload)) constraint so invalid JSON text cannot be stored. SHOW CREATE TABLE events displays the underlying LONGTEXT column and generated check constraint. Earlier versions do not add this constraint automatically.
This constraint checks JSON syntax only. To validate a document’s required fields or values, use JSON_SCHEMA_VALID() from MariaDB 11.1. For an explicit syntax check on arbitrary text, use JSON_VALID(). MySQL’s function with the same name uses a different JSON Schema draft; see the MySQL and MariaDB comparison before sharing schemas between the engines.
Text comparison and duplicate keys
Because MariaDB stores JSON as text, ordinary equality compares the text, including whitespace and object member order. Use JSON_EQUALS() when you need JSON-aware equality that ignores those differences.
The JSON text is retained verbatim. If an object contains duplicate keys, functions such as JSON_EXTRACT() expose only the first matching key-value pair. Avoid duplicate keys when the JSON will be read by SQL or other applications.
Compatibility with MySQL
MySQL stores JSON in a binary format; MariaDB stores its JSON alias as LONGTEXT. Compare this page with the MySQL JSON data type reference when moving schemas or queries between the two products. Row-based replication of JSON columns from MySQL to MariaDB does not work directly. MariaDB documents statement-based replication or converting the MySQL column to TEXT as alternatives; see its JSON migration notes.
For JSON constructors and query functions, see the MariaDB JSON function references.