You are viewing the archived documentation of TiDB, which no longer receives updates.

View latest LTS version docs

JSON Functions That Create JSON Values

This document describes JSON functions that create JSON values.

JSON_ARRAY()

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)

JSON_OBJECT()

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)

JSON_QUOTE()

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