What's new in Valkey 9.0? Discover new features and improvements. Read the announcement.

JSON.ARRAPPEND

Append one or more values to the array values at the path.

Usage
JSON.ARRAPPEND key path json ...
Complexity
O(N) where N is the number of values
Module
valkey-json
Since module version
1.0.0
ACL Categories
@json, @write, @fast

Append one or more values to the array values at the path.

Examples

Enhanced path syntax:

127.0.0.1:6379> JSON.SET k1 . '[[], ["a"], ["a", "b"]]'
OK
127.0.0.1:6379> JSON.ARRAPPEND  k1 $[*] '"c"'
1) (integer) 1
2) (integer) 2
3) (integer) 3
127.0.0.1:6379> JSON.GET k1
"[[\"c\"],[\"a\",\"c\"],[\"a\",\"b\",\"c\"]]"

Restricted path syntax:

127.0.0.1:6379> JSON.SET k1 . '[[], ["a"], ["a", "b"]]'
OK
127.0.0.1:6379> JSON.ARRAPPEND  k1 [-1] '"c"'
(integer) 3
127.0.0.1:6379> JSON.GET k1
"[[],[\"a\"],[\"a\",\"b\",\"c\"]]"

Replies

RESP2

  • If the path is enhanced syntax:
    • Array reply: Array of integers representing the new length of the array at each path.
    • Nil reply: For each path where the value is not an array.
  • If the path is restricted syntax:
    • Integer reply: The array's new length.
    • Integer reply: If multiple array values are selected, the command returns the new length of the last updated array.
  • Simple error reply:
    • if the path does not exist.
    • if the value at the path is not an array (only for restricted syntax).

RESP3

  • If the path is enhanced syntax:
    • Array reply: Array of integers representing the new length of the array at each path.
    • Null reply: For each path where the value is not an array.
  • If the path is restricted syntax:
    • Integer reply: The array's new length.
    • Integer reply: If multiple array values are selected, the command returns the new length of the last updated array
  • Simple error reply:
    • if the path does not exist.
    • if the value at the path is not an array (only for restricted syntax).