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

mysql> select json_length('true');
+---------------------+
| json_length('true') |
+---------------------+
|                NULL |
+---------------------+

mysql> select json_length('[1,2,3]');
+------------------------+
| json_length('[1,2,3]') |
+------------------------+
|                      3 |
+------------------------+

mysql> select json_length('{"a": 1, "b": 2}');
+---------------------------------+
| json_length('{"a": 1, "b": 2}') |
+---------------------------------+
|                               2 |
+---------------------------------+

Info

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

Was this article useful?