New versions: Dev (3.14) | Latest (3.13) | 3.12

JSON_ARRAY

Applies to ✅ 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, COCKROACHDB, POSTGRES
json_build_array(1, 2)

-- DB2, H2, MARIADB, MYSQL, ORACLE
JSON_ARRAY(1, 2)

-- ACCESS, ASE, AURORA_MYSQL, CUBRID, DERBY, FIREBIRD, HANA, HSQLDB, INFORMIX, INGRES, MEMSQL, REDSHIFT, SQLDATAWAREHOUSE, 
-- SQLITE, SQLSERVER, SYBASE, TERADATA, VERTICA
/* UNSUPPORTED */

(These are currently generated with jOOQ 3.14, see #10141)

The jOOQ Logo