website/docs/commands/json.md
Below is the full list of JSON Module commands and their implementation status in Garnet.
Note that this list is subject to change as we continue to expand our API command support with the help of our growing community.
| Command | Implemented in Garnet | Notes |
|---|---|---|
| JSON.GET | ➕ | |
| JSON.SET | ➕ | |
| JSON.DEL | ➖ | |
| JSON.TYPE | ➖ | |
| JSON.NUMINCRBY | ➖ | |
| JSON.NUMMULTBY | ➖ | |
| JSON.STRAPPEND | ➖ | |
| JSON.STRLEN | ➖ | |
| JSON.ARRAPPEND | ➖ | |
| JSON.ARRINDEX | ➖ | |
| JSON.ARRINSERT | ➖ | |
| JSON.ARRLEN | ➖ | |
| JSON.ARRPOP | ➖ | |
| JSON.ARRTRIM | ➖ | |
| JSON.OBJKEYS | ➖ | |
| JSON.OBJLEN | ➖ |
JSON.GET key [INDENT indent-string] [NEWLINE newline-string] [SPACE space-string] [path [path ...]]
Returns one of the following:
# Store a complex JSON object
JSON.SET example $ '{"name":"John","address":{"city":"London","postal":"SW1A"},"contacts":[{"type":"email","value":"[email protected]"},{"type":"phone","value":"123-456-789"}]}'
# Get entire document with pretty printing
JSON.GET example . INDENT " " NEWLINE "\n"
-> {"name":"John","address":{"city":"London","postal":"SW1A"},"contacts":[{"type":"email","value":"[email protected]"},{"type":"phone","value":"123-456-789"}]}
# Get multiple specific paths
JSON.GET example .name .address.city .contacts[0].value
-> ["John","London","[email protected]"]
# Get array elements with filter
JSON.GET example .contacts[?(@.type=="email")].value
-> ["[email protected]"]
JSON.SET key path value [NX | XX]
Returns one of:
# Set with NX (only if not exists)
JSON.SET user:3 $ '{"name":"Bob"}' NX
-> OK
# Set with XX (only if exists)
JSON.SET user:3 .age '25' XX
-> OK
# Modify nested array
JSON.SET user:3 .profile.interests[1] '"reading"'
-> OK
| Path Type | Syntax | Description | Example | Notes |
|---|---|---|---|---|
| Root | . or $ | References the root JSON document | JSON.GET key $ | Both notations supported |
| Property Access | .property or $.property | Accesses direct property of object | JSON.GET key $.name | Case sensitive |
| Nested Property | .prop1.prop2 or $.prop1.prop2 | Accesses nested object properties | JSON.GET key $.address.city | |
| Array Index | .array[n] or $.array[n] | Accesses array element at index n | JSON.GET key $.users[0] | Zero-based indexing |
| Array Slice | .array[start:end] | Retrieves array elements from start to end | JSON.GET key $.users[1:3] | End index is exclusive |
| Array Last Element | .array[-1] | Accesses last element of array | JSON.GET key $.users[-1] | |
| All Array Elements | .[*] or $[*] | Selects all elements in array | JSON.GET key $[*] | |
| Array Filter | .[?(@.prop==value)] | Filters array elements by condition | JSON.GET key $.users[?(@.age>21)] | |
| Multiple Paths | .prop1 .prop2 | Retrieves multiple paths at once | JSON.GET key $.name $.age | |
| Wildcard | .* or $.* | Selects all properties of object | JSON.GET key $.address.* | |
| Array Append | .[+] | Appends to array (SET only) | JSON.SET key $.list[+] value | Not supported as of now |
| Array Range | .[start:] | Selects elements from start to end | JSON.GET key $.list[2:] | |
| Conditional | .[?(@.size=="L")] | Complex array filtering | JSON.GET key $.items[?(@.size=="L")] | Supports multiple conditions |
| Nested Arrays | .[*][0] or $[*][0] | Access nested array elements | JSON.GET key $.matrix[*][0] |
Special Considerations: