Available in versions: Dev (3.22) | Latest (3.21) | 3.20 | 3.19 | 3.18 | 3.17 | 3.16 | 3.15 | 3.14 | 3.13 | 3.12
JSON_ARRAY
Supported by ✅ Open Source Edition ✅ Express Edition ✅ Professional Edition ✅ Enterprise Edition
The JSON_ARRAY function is used to produce simple JSON arrays from scalar values, without aggregation(see also JSON_ARRAYAGG).
SELECT json_array(author.first_name, author.last_name) FROM author
create.select(jsonArray(AUTHOR.FIRST_NAME, AUTHOR.LAST_NAME))
.from(AUTHOR)
.fetch();
The result would look like this:
+----------------------+ | json_array | +----------------------+ | ["Paulo", "Coelho"] | | ["George", "Orwell"] | +----------------------+
Dialect support
This example using jOOQ:
jsonArray(val(1), val(2))
Translates to the following dialect specific expressions:
Aurora Postgres, Postgres, YugabyteDB 2.25+
json_build_array(cast(1 AS int), cast(2 AS int))
BigQuery, DB2 11+, DuckDB, H2, MariaDB 10.2+, MySQL 5.7+, Oracle 23ai+, SQLServer 2022+, SQLite, Spanner
json_array(1, 2)
ClickHouse
toJSONString(tuple(1, 2))
CockroachDB
json_build_array(cast(1 AS int4), cast(2 AS int4))
Databricks
to_json(ARRAY( cast(1 AS variant), cast(2 AS variant) ))
Oracle 18c to 21c
json_array(nvl(NULL, 1), nvl(NULL, 2))
SQLServer 2016 to 2017
json_modify(
json_modify(
'[]',
'append $',
1
),
'append $',
2
)
Snowflake
array_construct(coalesce(
to_variant(1),
parse_json('null')
), coalesce(
to_variant(2),
parse_json('null')
))
Trino
cast(
ARRAY[
cast(1 AS json),
cast(2 AS json)
]
AS json
)
ASE, Access, Aurora MySQL, DB2 9 to 10, Exasol, Firebird, HSQLDB, Hana, Informix, MariaDB 10.0 to 10.1, MemSQL, MySQL 5.6, Redshift, SQLDataWarehouse, SQLServer 2012 to 2014, Sybase, Teradata, Vertica, YugabyteDB 2.9
/* UNSUPPORTED */
Generated with jOOQ 3.21. Support in older jOOQ versions may differ. Translate your own SQL on our website
Feedback
Do you have any feedback about this page? We'd love to hear it!