JSON_KEYS
Description
This function searches for keys from the top-level values of a JSON object and returns an array of keys corresponding to the specified path.
Syntax
JSON_KEYS(json_doc[, path])
Remarks
The json_doc parameter specifies the JSON document, and path is the path parameter. If any parameter is NULL, the function returns NULL.
If the json_doc parameter does not specify an object, or the path (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
SELECT JSON_KEYS('{"a": 1, "b": {"c": 20}}', '$.b');
+----------------------------------------------+
| JSON_KEYS('{"a": 1, "b": {"c": 20}}', '$.b') |
+----------------------------------------------+
| ["c"] |
+----------------------------------------------+
1 row in set (0.001 sec)
SELECT JSON_KEYS('{"a": 1, "b": {"c": 20}}');
+---------------------------------------+
| JSON_KEYS('{"a": 1, "b": {"c": 20}}') |
+---------------------------------------+
| ["a", "b"] |
+---------------------------------------+
1 row in set (0.001 sec)