The JSON alias was added in MariaDB 10.2.7. This was done to make it possible to use JSON columns in statement based replication from MySQL to MariaDB and to make it possible for MariaDB to read mysqldumps from MySQL.
JSON is an alias for LONGTEXT introduced for compatibility reasons with MySQL's JSON data type. MariaDB implements this as a LONGTEXT rather, as the JSON data type contradicts the SQL standard, and MariaDB's benchmarks indicate that performance is at least equivalent.
In order to ensure that a a valid json document is inserted, the JSON_VALID function can be used as a CHECK constraint. This constraint is automatically included for types using the JSON alias from MariaDB 10.4.3.
CREATE TABLE t (j JSON); DESC t; +-------+----------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+----------+------+-----+---------+-------+ | j | longtext | YES | | NULL | | +-------+----------+------+-----+---------+-------+
With validation:
CREATE TABLE t2 ( j JSON CHECK (JSON_VALID(j)) ); INSERT INTO t2 VALUES ('invalid'); ERROR 4025 (23000): CONSTRAINT `j` failed for `test`.`t2` INSERT INTO t2 VALUES ('{"id": 1, "name": "Monty"}'); Query OK, 1 row affected (0.13 sec)
The JSON type in MySQL stores the JSON object in a compact form, not as LONGTEXT as in MariaDB. This means that row based replication will not work for JSON types from MySQL to MariaDB.
There are a a few different ways to solve this:
MariaDB can't directly access MySQL's JSON format.
There are a a few different ways to move the table to MariaDB:
© 2019 MariaDB
Licensed under the Creative Commons Attribution 3.0 Unported License and the GNU Free Documentation License.
https://mariadb.com/kb/en/json-data-type/