创建 JSON 值

Exisi 2023-01-23 19:07:51
Categories: Tags:

函数

说明

JSON_ARRAY()

创建 JSON 数组

JSON_OBJECT()

创建 JSON 对象

JSON_QUOTE()

引用 JSON 文档

 

 

 

JSON_ARRAY([val[, val] ...])

评估一个(可能为空的)值列表并返回一个包含这些值的 JSON 数组。

示例

mysql> SELECT JSON_ARRAY(1, "abc", NULL, TRUE, CURTIME());

+-----------------------------------------------------------+

|  JSON_ARRAY(1, "abc", NULL, TRUE, CURTIME())  |

+-----------------------------------------------------------+

|          [1, "abc", null, true, "11:30:24.000000"]            |

+-----------------------------------------------------------+

 

 

 

JSON_OBJECT([key, val[, key, val] ...])

示例

mysql> SELECT JSON_OBJECT('id', 87, 'name', 'carrot');

+--------------------------------------------------+

|  JSON_OBJECT('id', 87, 'name', 'carrot')  |

+--------------------------------------------------+

|  {"id": 87, "name": "carrot"}                          |

+--------------------------------------------------+

 

 

 

JSON_QUOTE(string)

 

 

示例

mysql> SELECT JSON_QUOTE('null'), JSON_QUOTE('"null"');

+--------------------------+----------------------------+

| JSON_QUOTE('null') | JSON_QUOTE('"null"') |

+--------------------------+----------------------------+

| "null"                           |              "\"null\""           |

+--------------------------+----------------------------+

mysql> SELECT JSON_QUOTE('[1, 2, 3]');

+-------------------------------+

| JSON_QUOTE('[1, 2, 3]') |

+-------------------------------+

| "[1, 2, 3]"                            |

+-------------------------------+

 

 



来自 <https://dev.mysql.com/doc/refman/8.0/en/json-creation-functions.html>