JSON_KEYS()
All functions > JSON > JSON_KEYS()
Returns the keys of a JSON object as an array of strings.
Signatures
Returns: An array of the top-level keys in the object
JSON_KEYS(expr: JSON) → ARRAY(VARCHAR) sql
| Parameter | Type | Required | Description |
|---|---|---|---|
expr | JSON | Yes | A JSON expression that is an object |
Notes
- Returns the top-level keys of a JSON object, sorted by code point
- Key order is not part of a JSON value, so the keys are sorted on every backend; document order is not kept
- Returns NULL if the input is NULL
- Returns NULL if the input is not a JSON object
- Only returns top-level keys; nested object keys are not included
- Use with JSON_EXTRACT to get keys of nested objects
Availability
| Status | Backends |
|---|---|
| Not available | mysql |
See also
Examples
Edge cases
FeatureQL
RETURN
-- Get keys from a simple object (sorted, not in document order)
f1 := JSON_KEYS(JSON_PARSE('{"name": "Alice", "age": 30}')),
-- Get keys from a nested object
f2 := JSON_KEYS(
JSON_EXTRACT(
JSON_PARSE('{"user": {"id": 1, "role": "admin"}}'),
'$.user'
)
)
;Result
| f1 ARRAY | f2 ARRAY |
|---|---|
| [age, name] | [id, role] |