JSON function (only supported in version 5.7)
Command: json_object (function)
Function: Convert json string
Application scenarios: Specify data conversion json string
Example:
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)
Including 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_valid() to determine whether it is a json string:
select json_valid('{"name": "andyqian", "database": "MySQL"}');
It is 1 when it is a valid json string.
Invalid json string is 0.
There are many other methods, so I won’t demonstrate them one by one.
The above is the detailed content of How MySQL uses JSON functions. For more information, please follow other related articles on the PHP Chinese website!