In the MySQL
5.7.7 JSON labs release, we have introduced a new data type
for storing JSON data in MySQL tables. Now you can do this:
mysql> CREATE TABLE employees (data JSON);
Query OK, 0 rows affected (0,01 sec)
mysql> INSERT INTO employees VALUES ('{"id": 1, "name": "Jane"}');
Query OK, 1 row affected (0,00 sec)
mysql> INSERT INTO employees VALUES ('{"id": 2, "name": "Joe"}');
Query OK, 1 row affected (0,00 sec)
mysql> select * from employees;
+---------------------------+
| data |
+---------------------------+
| {"id": 1, "name": "Jane"} |
| {"id": 2, "name": "Joe"} |
+---------------------------+
2 rows in set (0,00 sec)
Sure, you could always store JSON data in a TEXT or VARCHAR
column, but having a native data type for JSON provides some
major benefits over that approach:
-
Document Validation
Only …
[Read more]