JSON类型相关函数
JSON_ARRAY()
返回json数组
mysql> SELECT JSON_ARRAY(1,'A',true);;+------------------------+| JSON_ARRAY(1,'A',true) |+------------------------+| [1, "A", true] |+------------------------+
JSON_OBJECT()
返回json对象
mysql> SELECT JSON_OBJECT("name",'小明',"age",18);;+---------------------------------------+| JSON_OBJECT("name",'小明',"age",18) |+---------------------------------------+| {"age": 18, "name": "小明"} |+---------------------------------------+1 row in set (0.00 sec)
插入JSON数据
-- 插入json数据mysql> INSERT INTO json_tab(content) VALUES (JSON_OBJECT("id",1,"name","小明","age",18));;-- 查看数据mysql> SELECT * FROM json_tab;;+----+----------------------------------------+| id | content |+----+----------------------------------------+| 1 | {"id": 1, "age": 18, "name": "小明"} |+----+----------------------------------------+
创建JSON表
mysql 8 开始有
JSON关键字来创建JSON对象
mysql> CREATE TABLE json_tab(-> id INT AUTO_INCREMENT PRIMARY KEY,-> content JSON NOT NULL-> );;
