Working with JSON Documents

1. Setting JSON Documents

CommandDescription
JSON.SET key path value [NX|XX]Use $ for root
JSON.SET user:42 $ '{"name":"Alice","age":30,"tags":["admin"]}'

2. Getting JSON Values

CommandOptions
JSON.GET key [INDENT s] [NEWLINE n] [SPACE s] [path ...]Multiple JSONPaths in one call
JSON.MGET k1 k2 ... pathSame path across keys

3. Deleting JSON Keys

CommandDescription
JSON.DEL key [path]Remove field or entire doc
JSON.FORGETAlias for JSON.DEL

4. Using JSONPath Queries

ExpressionMatch
$Root
$.fieldDirect child
$..fieldRecursive descent
$.arr[0]Array index
$.arr[*]All elements
$.arr[?(@.age > 18)]Filter

5. Handling Nested Objects

JSON.SET user:42 $.address '{"city":"NYC","zip":"10001"}'
JSON.GET user:42 $.address.city
PatternDetail
Partial updateSET subtree path without rewriting whole doc

6. Getting Object Keys

CommandReturns
JSON.OBJKEYS key [path]Keys at object path

7. Getting Object Length

CommandReturns
JSON.OBJLEN key [path]Key count of object

8. Incrementing Numeric Values

CommandDescription
JSON.NUMINCRBY key path nAtomic numeric increment
JSON.NUMMULTBY key path nAtomic multiply DEPRECATED

9. Appending to Strings

CommandDescription
JSON.STRAPPEND key [path] "value"Append to JSON string

10. Getting String Length

CommandReturns
JSON.STRLEN key [path]Character length

11. Appending to Arrays

CommandDescription
JSON.ARRAPPEND key path v [v ...]Append elements; returns new length

12. Getting Array Length

CommandReturns
JSON.ARRLEN key [path]Element count

13. Inserting Array Elements

CommandDescription
JSON.ARRINSERT key path index v [v ...]Insert at index
JSON.ARRINDEX key path scalar [start [stop]]Find index of scalar

14. Popping Array Elements

CommandDescription
JSON.ARRPOP key [path [index]]Remove and return; default last

15. Trimming Arrays

CommandDescription
JSON.ARRTRIM key path start stopKeep only range