PostgreSQL jsonb_array_length() Function
The PostgreSQL jsonb_array_length() function returns the length (the number of top-level elements in the array) of a specified JSONB array.
jsonb_array_length() Syntax
This is the syntax of the PostgreSQL jsonb_array_length() function:
jsonb_array_length(any_array JSONB) -> INTEGER
Parameters
any_array-
Required. A JSONB array.
Return value
The PostgreSQL jsonb_array_length() function returns the length of a JSONB array, that is the number of top-level elements in the array.
jsonb_array_length() Examples
This example shows how to use the PostgreSQL jsonb_array_length() function to get the length of a JSONB array.
SELECT jsonb_array_length('[1, 2, [3, 4]]');
jsonb_array_length
-------------------
3Here, the [1, 2, [3, 4]] array contains 3 top-level elements, so the jsonb_array_length() function returns 3.