JSON_OBJECT
Descriptionβ
Generate a json object containing the specified Key-Value, an exception error is returned when Key is NULL or the number of parameters are odd.
Syntaxβ
JSON_OBJECT (<key>, <value>[,<key>, <value>, ...])
Parametersβ
Parameter | Description |
---|---|
<key> | The Key value in the Key-Value of the generated json object. |
<value> | The Value value in the Key-Value of the generated json object. |
Return Valuesβ
Return a json object. Special cases are as follows:
- If no parameters are passed, return an empty json object.
- If the number of parameters passed is odd, return an exception error.
- If the passed Key is NULL, return an exception error.
- If the passed Value is NULL, the Value value of the Key-Value pair in the returned json object is NULL.
Examplesβ
select json_object();
+---------------+
| json_object() |
+---------------+
| {} |
+---------------+
select json_object('time',curtime());
+--------------------------------+
| json_object('time', curtime()) |
+--------------------------------+
| {"time": "10:49:18"} |
+--------------------------------+
SELECT json_object('id', 87, 'name', 'carrot');
+-----------------------------------------+
| json_object('id', 87, 'name', 'carrot') |
+-----------------------------------------+
| {"id": 87, "name": "carrot"} |
+-----------------------------------------+
select json_object('username',null);
+---------------------------------+
| json_object('username', 'NULL') |
+---------------------------------+
| {"username": NULL} |
+---------------------------------+
select json_object(null,null);
ERROR 1105 (HY000): errCode = 2, detailMessage = json_object key can't be NULL: json_object(NULL)