Available in versions: Dev (3.20)

This documentation is for the unreleased development version of jOOQ. Click on the above version links to get this documentation for a supported version of jOOQ.

JSON_ARRAY_LENGTH

Applies to ✅ Open Source Edition   ✅ Express Edition   ✅ Professional Edition   ✅ Enterprise Edition

The JSON_ARRAY_LENGTH function is used to count the number of elements in a JSON_ARRAY.

SELECT
  json_array_length(json_array(1, 2))
create.select(jsonArrayLength(jsonArray(1, 2)))
      .fetch();

The result would look like this:

+-------------------+
| json_array_length |
+-------------------+
|                 1 |
+-------------------+

Dialect support

This example using jOOQ:

jsonArrayLength(val(json("[1,2]")))

Translates to the following dialect specific expressions:

Aurora Postgres, CockroachDB, Postgres, YugabyteDB

json_array_length(CAST('[1,2]' AS json))

BigQuery

array_length(json_query_array('[1,2]', '$'))

ClickHouse

JSONArrayLength('[1,2]')

DuckDB, SQLite

json_array_length('[1,2]')

MariaDB, MySQL

json_length('[1,2]')

Oracle

(
  SELECT count(*)
  FROM JSON_TABLE(
    '[1,2]',
    '$[*]'
    COLUMNS (x varchar2(4000) PATH '$')
  )
)

SQLServer

(
  SELECT count(*)
  FROM openjson('[1,2]')
)

ASE, Access, Aurora MySQL, DB2, Derby, Exasol, Firebird, H2, HSQLDB, Hana, Informix, MemSQL, Redshift, SQLDataWarehouse, Snowflake, Sybase, Teradata, Trino, Vertica

/* UNSUPPORTED */
Generated with jOOQ 3.20. Translate your own SQL on our website

Feedback

Do you have any feedback about this page? We'd love to hear it!

The jOOQ Logo