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