title | summary |
---|---|
JSON Functions That Create JSON Values |
Learn about JSON functions that create JSON values. |
This document describes JSON functions that create JSON values.
The JSON_ARRAY([val[, val] ...])
function evaluates a (possibly empty) list of values and returns a JSON array containing those values.
SELECT JSON_ARRAY(1,2,3,4,5), JSON_ARRAY("foo", "bar");
+-----------------------+--------------------------+
| JSON_ARRAY(1,2,3,4,5) | JSON_ARRAY("foo", "bar") |
+-----------------------+--------------------------+
| [1, 2, 3, 4, 5] | ["foo", "bar"] |
+-----------------------+--------------------------+
1 row in set (0.00 sec)
The JSON_OBJECT([key, val[, key, val] ...])
function evaluates a (possibly empty) list of key-value pairs and returns a JSON object containing those pairs.
SELECT JSON_OBJECT("database", "TiDB", "distributed", TRUE);
+------------------------------------------------------+
| JSON_OBJECT("database", "TiDB", "distributed", TRUE) |
+------------------------------------------------------+
| {"database": "TiDB", "distributed": true} |
+------------------------------------------------------+
1 row in set (0.00 sec)
The JSON_QUOTE(str)
function returns a string as a JSON value with quotes.
SELECT JSON_QUOTE('The name is "O\'Neil"');
+-------------------------------------+
| JSON_QUOTE('The name is "O\'Neil"') |
+-------------------------------------+
| "The name is \"O'Neil\"" |
+-------------------------------------+
1 row in set (0.00 sec)