SingleStore DB

JSON_LENGTH

Computes the length of a JSON map or array.

JSON_LENGTH(json)
Arguments
  • json: a valid JSON array or map.

Return Value
  • the length as an integer

  • SQL NULL if json is not a valid JSON array or map

Examples
SELECT JSON_LENGTH('true');
+---------------------+
| JSON_LENGTH('true') |
+---------------------+
|                NULL |
+---------------------+

SELECT JSON_LENGTH('[1,2,3]');
+------------------------+
| JSON_LENGTH('[1,2,3]') |
+------------------------+
|                      3 |
+------------------------+

SELECT JSON_LENGTH('{"a": 1, "b": 2}');
+---------------------------------+
| JSON_LENGTH('{"a": 1, "b": 2}') |
+---------------------------------+
|                               2 |
+---------------------------------+

Notice

A JSON or Javascript null value is distinct from SQL NULL.