MySQL如何使用JSON函数

JSON函数(5.7版本才支持)

命令:json_object(函数)

作用:转换json字符串

应用场景:指定数据转换json字符串

例子:

mysql> select json_object("name","andyqian","database","MySQL");
+---------------------------------------------------+
| json_object("name","andyqian","database","MySQL") |
+---------------------------------------------------+
| {"name": "andyqian", "database": "MySQL"}  |
+---------------------------------------------------+
1 row in set (0.00 sec)

其中包括json_array:

mysql> select json_array("name","andyqian","database","MySQL");
+--------------------------------------------------+
| json_array("name","andyqian","database","MySQL") |
+--------------------------------------------------+
| ["name", "andyqian", "database", "MySQL"] |
+--------------------------------------------------+
1 row in set (0.00 sec)

判断是否为json字符串的json_valid():

select json_valid('{"name": "andyqian", "database": "MySQL"}');

其中为有效json字符串时为1。

无效json字符串时为0.

还有很多方法,不再一一演示。

以上就是MySQL如何使用JSON函数的详细内容,更多请关注www.sxiaw.com其它相关文章!