Purpose
This function searches from the top-level value of a JSON object and returns an array of keys for the corresponding paths.
Syntax
JSON_KEYS(json_doc[, path])
Description
The json_doc parameter specifies the JSON document, and path is a path parameter. If either parameter is NULL, NULL is returned.
If the json_doc parameter does not specify an object, or if the path (if provided) does not correspond to any path, NULL is returned.
An error will be returned in the following scenarios:
The
json_docparameter is not a valid JSON document.The
pathparameter is not a valid path expression.The
pathparameter contains the * or ** wildcard character.
If the selected object is empty, the result is empty. If a top-level value contains nested child objects, the return value does not include the keys from these child objects.
Examples
obclient> SELECT JSON_KEYS('{"a": 1, "b": {"c": 20}}', '$.b');
+----------------------------------------------+
| JSON_KEYS('{"a": 1, "b": {"c": 20}}', '$.b') |
+----------------------------------------------+
| ["c"] |
+----------------------------------------------+
1 row in set
obclient> SELECT JSON_KEYS('{"a": 1, "b": {"c": 20}}');
+---------------------------------------+
| JSON_KEYS('{"a": 1, "b": {"c": 20}}') |
+---------------------------------------+
| ["a", "b"] |
+---------------------------------------+
1 row in set