Skip to content

Latest commit

 

History

History
64 lines (48 loc) · 2.05 KB

json-functions-create.md

File metadata and controls

64 lines (48 loc) · 2.05 KB
title summary
JSON Functions That Create JSON Values
Learn about JSON functions that create JSON values.

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)

See also