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
- Key order depends on the backend and is not guaranteed
- 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
See also
Examples
Edge cases
FeatureQL
SELECT
f1 := JSON_KEYS(JSON_PARSE('{"name": "Alice", "age": 30}')), -- Get keys from a simple object
f2 := JSON_KEYS(JSON_EXTRACT(JSON_PARSE('{"user": {"id": 1, "role": "admin"}}'), '$.user')) -- Get keys from a nested object
;Result
| f1 ARRAY | f2 ARRAY |
|---|---|
| [name, age] | [id, role] |
On this page