As the lead for a team's Redis usage, how do you decide when to adopt the JSON type rather than keep hashes or serialized strings?
answer
- how is the value really accessed
- nesting versus flat fields
- who pays in memory and processing
- fleet version and module configuration
- rules to set once adopted
basics
~20 sAdopt the Redis JSON type when documents are truly nested and services often read or change parts of them. Keep hashes for flat objects or per-field expiry, and strings for values always handled whole, because JSON generally costs most.
solid answer
~50 sI decide from how the value is accessed, measured on real traffic. If services read and write the whole object, a string is cheapest and JSON buys nothing. If the object is flat, or fields need their own expiry, a hash wins: Redis's guidance gives hashes lower overhead and faster field access, and only hashes expire fields. JSON earns its cost when data is nested and several services change parts of it, or when query-engine indexes must reach nested fields. Then I check what adoption costs: memory measured on real documents, every server on Redis 8 with modules loaded, and client code that handles JSONPath replies. If we adopt, I set rules: `$` paths only, lines addressed by identity, a per-document size budget, and migration under new key names. I would revisit if most access stays whole-document.
go deeper
Know the three choices and one reason for each: a string for whole values, a hash for flat fields, and JSON for nested documents with partial access.
Use the access pattern to pick a type for a concrete object, and name what each choice costs, including that only hashes offer per-field expiry among the three.
Bring measurements: bytes per document on real data and the share of whole-document reads. Call out the migration trap, since SET overwrites any type and JSON commands refuse string keys.
Own the standard, not one key: an access-based rule, a shared reply helper, a schema owner and a per-family review, plus the fleet and licence questions behind moving to Redis 8.
## The decision is about access, not about the data being JSON Almost any object can be written as JSON text, so "our data is JSON" settles nothing. The real question is how the value is read and changed, and by whom. Redis's own comparison calls its advice rules of thumb, and it gives this order for documents: JSON generally has the highest requirements for memory and processing, followed by hashes, then strings. | Type | Fits when | What you give up | |---|---|---| | Serialized string | The value is read and written whole, by one owner | Partial reads and writes, and any server-side view inside it | | Hash | The object is flat, with fields read or changed singly, or fields need their own expiry | Nesting, since field values are flat strings | | JSON type | Data is nested, and parts of it are read or changed by several services | More memory and processing, and a richer reply contract to handle | ## Signals for adopting - **Nested structure you address.** Line items inside a cart, read and changed one at a time. Redis's decision guide starts here: JSON is the only one of the three that supports deeply nested structures. - **Concurrent partial changes.** Several services change different parts, and today they either lose updates or run `WATCH` retry loops on large values. - **Traffic on large documents.** Services fetch a large document to use one member. - **Query needs on nested fields.** A team that needs query-engine indexes over nested data needs JSON for those structures. Index design itself is a separate decision. ## Signals against - **Whole-value access.** A cached API response is always read whole. JSON adds memory and tree work for nothing. - **Flat objects.** A hash carries lower overhead and faster field access, by the same guidance. - **Field-level expiry.** The guide says only hashes support this. A JSON key expires as a whole. - **Huge documents on a shared instance.** Partial access helps, but whole-document reads and recursive `$..` paths are documented as O(N) in the size of the key, and a long command delays whatever is queued behind it. ## What adoption costs a team 1. **Memory.** Measure real documents on your Redis version, on a test instance, using `used_memory`. In the docs' table the smallest example file takes over double its text size, and the largest about 1.2 times. 2. **Fleet state.** JSON has been part of Redis Open Source only since **8.0**. Before that it is a separate module. Teams still on 7.x must either upgrade or run the module. On 8.x a core-only source build has no JSON commands, so check every environment. 3. **Licensing.** Redis 8.0 and later are offered under your choice of RSALv2, SSPLv1 or AGPLv3, and 7.2 and earlier remain BSD. Moving a fleet to 8 to obtain JSON is a licence decision for whoever owns that. 4. **Client code.** Replies differ between JSONPath and legacy paths, and between RESP2 and RESP3, and misses arrive as `[]`, `null` or nil rather than errors. That logic has to live in one tested place. ## The standard to set if you adopt 1. **`$` paths only**, with one client helper that treats empty and null replies as failures. 2. **Address by identity**, never by a stored array position. 3. **A schema owner** for each shared document, because several writers still share one shape. 4. **A size budget** per document, sampled regularly, with a TTL for documents that go idle. 5. **New key names for migration**. `SET` overwrites any type, and JSON commands return `WRONGTYPE` on a string key, so changing a key's type in place breaks whichever side has not been deployed. ## When to revisit Review after a real period of production use. If telemetry shows most access still fetches whole documents, or memory grows faster than the partial-update benefit, go back to strings or hashes. Moving back means writing new keys again, so the choice is reversible per key family. Decide per family, not for the estate, because a cart and a cached response can reasonably land on different answers. Before approving a family, ask for three numbers: bytes per document on real data, the share of operations that touch part of a document, and the retry rate of the current approach. They settle most of these debates.
- A team wants JSON for a flat session object of ten small fields. What do you ask them?Whether any field is nested, and whether they need a query-engine index that a hash cannot serve. If not, a hash fits: field reads and increments are native, memory overhead is lower by Redis's guidance, and individual fields can expire. I would ask them to show the access pattern, and to name a concrete need that a hash fails to meet.
- How would you standardise this across several teams without blocking them?Publish a short decision guide based on access pattern, a shared client helper for paths and replies, and a required measurement of bytes per document before production. Decide by key family, not by service. Teams stay free to choose JSON with those three in place, and a periodic review catches families whose access turned out to be whole-document.
- Our payloads are JSON already, so the JSON type is automatically the right choice.
- The JSON type uses less memory than a hash because it is binary.
- A single JSON path can carry its own TTL, so hashes are unnecessary for field expiry.
- Adopting JSON needs no check of the fleet, since every Redis server includes it.
- Moving a key from string to JSON in place is safe during a rolling deploy.
Assumes Redis 8.10; adoption needs every server on Redis 8 with modules loaded, because the type joined Redis Open Source in 8.0.