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

Last update at: 2026/05/26 17:22:09