Purpose
Returns the maximum depth of the JSON document.
Syntax
JSON_DEPTH(json_doc)
Description
The json_doc parameter specifies the JSON document. If this parameter is NULL, NULL is returned.
An error occurs if the parameter is not a valid JSON document.
An empty array, an empty object, or a scalar value has a depth of 1. A non-empty array that contains only elements with a depth of 1 has a depth of 2. A non-empty object that contains only member values with a depth of 1 has a depth of 2. Otherwise, the JSON document has a depth greater than 2.
Examples
obclient> SELECT JSON_DEPTH('{}'), JSON_DEPTH('[]'), JSON_DEPTH('true');
+------------------+------------------+--------------------+
| JSON_DEPTH('{}') | JSON_DEPTH('[]') | JSON_DEPTH('true') |
+------------------+------------------+--------------------+
| 1 | 1 | 1 |
+------------------+------------------+--------------------+
1 row in set
obclient> SELECT JSON_DEPTH('[101, 202]'), JSON_DEPTH('[[], {}]');
+--------------------------+------------------------+
| JSON_DEPTH('[101, 202]') | JSON_DEPTH('[[], {}]') |
+--------------------------+------------------------+
| 2 | 2 |
+--------------------------+------------------------+
1 row in set
obclient> SELECT JSON_DEPTH('[101, {"a": 202}]');
+---------------------------------+
| JSON_DEPTH('[101, {"a": 202}]') |
+---------------------------------+
| 3 |
+---------------------------------+
1 row in set
obclient> SELECT JSON_DEPTH('{"a":101, "v":"aaa"}');
+------------------------------------+
| JSON_DEPTH('{"a":101, "v":"aaa"}') |
+------------------------------------+
| 2 |
+------------------------------------+
1 row in set