Skip to main content

JSON_ARRAY

Returns a JSON array whose elements are its arguments. Strings become JSON strings, numbers JSON numbers and NULL JSON null; a JSON value produced by another JSON function is embedded as JSON rather than as a string.

See also:
[SELECT] [JSON_OBJECT] [JSON_GROUP_ARRAY]


Syntax​

SELECT JSON_ARRAY([value, ...]) FROM <multipartIdentifier>;

Arguments​

value
Zero or more values.

Return Value(s)​

Returns a JSON array string.


Examples​

Build an array from literals​

The last element is embedded as an array because it comes from the JSON function:

SELECT JSON_ARRAY(1, 2.5, 'three', NULL, JSON('[4]')) AS v;
|----------------------------|
| v |
|----------------------------|
| [1,2.5,"three",null,[4]] |
|----------------------------|

Build an array from columns​

The following query returns the name, star count and fork count of each repository in a GitHub organization as one array:

SELECT name, JSON_ARRAY(name, stargazers_count, forks_count) AS stats
FROM github.repos.repos
WHERE org = 'stackql-labs';

For more information, see https://www.sqlite.org/json1.html#jarray