Generate a JSON array containing the specified elements. Returns an empty array when no parameters are passed.
JSON_ARRAY([<expression>, ...])
<expression>: Elements to be included in the JSON array. Can be single or multiple values of different types, including NULL.JSON: Returns a JSON array composed of the parameter list.
TO_JSON function, so parameters must be types supported by TO_JSONJSON_ARRAY_IGNORE_NULL.TO_JSON, you will get an error. You can first convert that parameter to String type, for example:select JSON_ARRAY(CAST(NOW() as String));
The NOW() function returns a DateTime type, which needs to be converted to String type using the CAST function
JSON_PARSE function to parse it as a JSON object:select JSON_ARRAY(JSON_PARSE('{"key": "value"}'));
select json_array() as empty_array, json_array(1) v1, json_array(1, 'abc') v2;
+-------------+------+-----------+ | empty_array | v1 | v2 | +-------------+------+-----------+ | [] | [1] | [1,"abc"] | +-------------+------+-----------+
select json_array(null) v1, json_array(1, null, 'I am a string') v2;
+--------+--------------------------+ | v1 | v2 | +--------+--------------------------+ | [null] | [1,null,"I am a string"] | +--------+--------------------------+
select json_array('item1', map(123, 'abc'));
ERROR 1105 (HY000): errCode = 2, detailMessage = Can not find the compatibility function signature: to_json(MAP<TINYINT,VARCHAR(3)>)
select json_array(1, cast(map('key', 'value') as json));
+--------------------------------------------------+
| json_array(1, cast(map('key', 'value') as json)) |
+--------------------------------------------------+
| [1,{"key":"value"}] |
+--------------------------------------------------+
select json_array('{"key1": "value", "key2": [1, "I am a string", 3]}');
+------------------------------------------------------------------+
| json_array('{"key1": "value", "key2": [1, "I am a string", 3]}') |
+------------------------------------------------------------------+
| ["{\"key1\": \"value\", \"key2\": [1, \"I am a string\", 3]}"] |
+------------------------------------------------------------------+
json_parse and then passed to json_arrayselect json_array(json_parse('{"key1": "value", "key2": [1, "I am a string", 3]}'));
+------------------------------------------------------------------------------+
| json_array(json_parse('{"key1": "value", "key2": [1, "I am a string", 3]}')) |
+------------------------------------------------------------------------------+
| [{"key1":"value","key2":[1,"I am a string",3]}] |
+------------------------------------------------------------------------------+