Purpose
This function searches for keys from the top-level value of a JSON object and returns an array of keys corresponding to the specified path.
Syntax
JSON_KEYS(json_doc[, path])
Parameters
The json_doc parameter specifies the JSON document, and the path parameter specifies the path. If any parameter is NULL, the function returns NULL.
If the json_doc parameter does not specify an object, or if the path parameter (if provided) does not correspond to any valid path, the function returns NULL.
The following situations will result in an error:
The
json_docparameter is not a valid JSON document.The
pathparameter is not a valid path expression.The
pathparameter contains the * or ** wildcard.
If the selected object is empty, the result is empty. If the top-level value is nested within a subobject, the returned value does not include keys from these subobjects.
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
