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))

ClickHouse

JSONArrayLength('[1,2]')

MariaDB, MySQL

json_length('[1,2]')

Oracle

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

SQLite

json_array_length('[1,2]')

SQLServer

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

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

/* UNSUPPORTED */

(These are currently generated with jOOQ 3.20, see #10141), or translate your own on our website

Feedback

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

The jOOQ Logo