json_array_length function

Returns the number of elements in the outermost JSON array.

Syntax

json_array_length(jsonArray)

Arguments

  • jsonArray: A JSON array.

Returns

An INTEGER.

The function returns NULL if jsonArray is not a valid JSON string or NULL.

Databricks Runtime versions

Note

Available in Databricks Runtime 8.0 and above.

Examples

> SELECT json_array_length('[1,2,3,4]');
 4
> SELECT json_array_length('[1,2,3,{"f1":1,"f2":[5,6]},4]');
 5
> SELECT json_array_length('[1,2');
 NULL