JSON.STRAPPEND
JSON.STRAPPEND key [path] value
- Available in:
- Redis Open Source / JSON 1.0.0
- Time complexity:
- O(1) when path is evaluated to a single value, O(N) when path is evaluated to multiple values, where N is the size of the key
- ACL categories:
-
@json,@write,@slow, - Compatibility:
- Redis Software and Redis Cloud compatibility
Appends a string to JSON strings at the paths matching a given path expression.
Required arguments
key
is a Redis key storing a value of type JSON.
value
is a string to append to the JSON strings at the paths matching path.
About using strings with JSON commands:
To specify a string as an array value to append, wrap the quoted string with an additional set of single quotes. Example: '"silver"'. For more detailed use, see Examples.Optional arguments
path
is either
- A JSONPath expression
- The root "
$", or any string that starts with "$." or "$[". - Resolves to all matching locations in
key.
- The root "
- A legacy path expression
- Any string that does not match the JSONPath syntax above.
- Allow the leading "
." to be omitted (for example, "name" and ".name" are equivalent). - Resolves to only the first matching location in
key.
Default: "." (legacy path pointing to the root of the document).
Examples
redis> JSON.SET doc $ '{"a":"foo", "nested": {"a": "hello"}, "nested2": {"a": 31}}'
OK
redis> JSON.STRAPPEND doc $..a '"baz"'
1) (integer) 6
2) (integer) 8
3) (nil)
redis> JSON.GET doc $
"[{\"a\":\"foobaz\",\"nested\":{\"a\":\"hellobaz\"},\"nested2\":{\"a\":31}}]"Redis Software and Redis Cloud compatibility
| Redis Software |
Redis Cloud |
Notes |
|---|---|---|
| ✅ Supported |
✅ Flexible & Annual ✅ Free & Fixed |
Return information
If path is a JSONPath expression:
- A simple error if
keydoes not exist. - An empty array reply if
pathhas no matches. - An array reply where each array element corresponds to one match:
nilif the match is not a string.- An integer reply: the new length of the string.
If path is a legacy path expression:
- A simple error if
keydoes not exist. - A simple error if
pathhas no matches. - A simple error if the first match is not a string.
- An integer reply: the new length of the string at the first match.