JSON.OBJKEYS
JSON.OBJKEYS key [path]
- Available in:
- Redis Open Source / JSON 1.0.0
- Time complexity:
- O(N) when path is evaluated to a single value, where N is the number of keys in the object, O(N) when path is evaluated to multiple values, where N is the size of the key
- ACL categories:
-
@json,@read,@slow, - Compatibility:
- Redis Software and Redis Cloud compatibility
Returns the key names of JSON objects located at the paths that match a given path expression.
Note:
A JSON object is a structure within a JSON document that contains an unordered set of key-value pairs (also called name-value pairs). Do not confuse Redis keys with JSON object keys.Required arguments
key
is a Redis key storing a value of type JSON.
Optional arguments
path
is either
- A JSONPath expression
- The root "
$", or any string that starts with "$." or "$[". - Resolves to all matching locations in
key.
- The root "
- A legacy path expression
- Any string that does not match the JSONPath syntax above.
- Allow the leading "
." to be omitted (for example, "name" and ".name" are equivalent). - Resolves to only the first matching location in
key.
Default: "." (legacy path pointing to the root of the document).
Examples
redis> JSON.SET doc $ '{"a":[3], "nested": {"a": {"b":2, "c": 1}}}'
OK
redis> JSON.OBJKEYS doc $..a
1) (nil)
2) 1) "b"
2) "c"Redis Software and Redis Cloud compatibility
| Redis Software |
Redis Cloud |
Notes |
|---|---|---|
| ✅ Supported |
✅ Flexible & Annual ✅ Free & Fixed |
Return information
If path is a JSONPath expression:
- A simple error if
keydoes not exist. - An empty array reply if
pathhas no matches. - An array reply where each array element corresponds to one match:
nilif the match is not an object.- An array reply of bulk string replies containing the object's key names if the match is an object.
If path is a legacy path expression:
nilifkeydoes not exist.nilifpathhas no matches.- A simple error if the first match is not an object.
- An array reply of bulk string replies containing the object's key names of the first match.