Purpose
JSON_KEYS() returns the keys from the top-level value of a JSON object as a JSON array. When a path argument is specified, it returns the top-level keys from the selected path.
Syntax
JSON_KEYS(json_doc[, path])
Note
json_doc specifies the name of the JSON document, and path specifies the path. If any argument is NULL, the return value is NULL.
If the specified json_doc is not an object, or the specified path does not correspond to any path, the return value is NULL.
An error occurs in the following cases:
The JSON document specified for
json_docis invalid.The path expression specified for
pathis invalid.The specified
pathcontains a * or ** wildcard.
If the selected object is empty, the result is empty. If the top-level value contains nested sub-objects, the return value does not include the keys from those sub-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