How do you set and retrieve a specific nested field within a JSON document using RedisJSON's path syntax?
Short answer
You use JSON.SET or JSON.GET along with a JSONPath expression that identifies the specific field you want to target, using a dollar sign to represent the document's root and dot notation to navigate into nested objects, letting you work with just the specific piece of data you…
Advertisement
AModel answer
You use JSON.SET or JSON.GET along with a JSONPath expression that identifies the specific field you want to target, using a dollar sign to represent the document's root and dot notation to navigate into nested objects, letting you work with just the specific piece of data you actually need.
Example
JSON.SET user:100 $.address.zipCode '"02108"' JSON.GET user:100 $.address.zipCode
Real-world example
An address update feature modifies just a user's zip code field directly within their stored JSON document, without touching any of the other unrelated fields in that same document.
Likely follow-ups
- What is the JSONPath syntax for accessing an item within an array?
- What happens if the specified path does not exist within the document?
Related topics