JSON Documents
Store structured documents and update individual fields through RedisJSON commands. Swytch includes the JSON.* command
family in its Redis server; you do not need to install a separate module.
JSON.SET product:42 $ '{"name":"tea","stock":10,"tags":["drink"]}'
JSON.GET product:42 $
JSON.NUMINCRBY product:42 $.stock -1
JSON.ARRAPPEND product:42 $.tags '"sale"'
JSON.GET product:42 $.stock
The final read returns [9]. JSONPath expressions beginning with $ return matching values using array semantics, even
when one value matches. Legacy paths such as .stock have different reply shapes; use the path style your client
expects.
Use JSON.SET to replace a document or a selected value, JSON.NUMINCRBY for numeric updates, and the array commands
to modify collections. These commands avoid fetching and rewriting an entire document in application code.
A JSON document is a distinct value type. To access a document stored with JSON.SET, use JSON.GET. A JSON string
stored with ordinary SET is still a string; it does not become a RedisJSON document automatically.
JSON documents use the same local and distributed key model as other structures. Choose tiering if documents must survive the loss of every in-memory holder.
See the JSON command reference for the supported command family. RedisJSON support is separate
from the Lua cjson library; review scripting compatibility when migrating scripts.