JSON_ARRAY_COUNT()

All functions > JSON > JSON_ARRAY_COUNT()

Returns the number of elements in a JSON array.

Signatures

Returns: The number of elements in the array

JSON_ARRAY_COUNT(expr: JSON) → BIGINT
sql
ParameterTypeRequiredDescription
exprJSONYesA JSON expression that is an array

Notes

  • Returns the length of a JSON array
  • Returns NULL if the input is NULL
  • Returns NULL if the input is not a JSON array
  • Use with JSON_EXTRACT to count elements in nested arrays
  • Equivalent to getting the size of a JSON array without unnesting it

See also

Examples

Edge cases

FeatureQL
SELECT
    -- Count elements in a simple array
    f1 := JSON_ARRAY_COUNT(JSON_PARSE('[1, 2, 3]')),
    -- Empty array returns 0
    f2 := JSON_ARRAY_COUNT(JSON_PARSE('[]')),
    -- Count elements in a nested array
    f3 := JSON_ARRAY_COUNT(
        JSON_EXTRACT(JSON_PARSE('{"items": [10, 20, 30, 40]}'), '$.items')
    )
;
Result
f1 BIGINTf2 BIGINTf3 BIGINT
304

Last update at: 2026/06/20 10:08:10