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.
还有很多方法,不再一一演示。
【文章原创作者:欧洲服务器 http://www.558idc.com/helan.html 复制请保留原URL】