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

JSON.ARRPOP

Remove and returns the element at the given index. Popping an empty array returns null.

Usage
JSON.ARRPOP key [path] [index]
Complexity
O(N) where N is the number of jsons arrays matched by the path.
Module
valkey-json
Since module version
1.0.0
ACL Categories
@write, @fast, @json

Remove and return element at the index from the array. Popping an empty array returns null.

Examples

Enhanced path syntax:

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

Restricted path syntax:

127.0.0.1:6379> JSON.SET k1 . '[[], ["a"], ["a", "b"]]'
OK
127.0.0.1:6379> JSON.ARRPOP k1
"[\"a\",\"b\"]"
127.0.0.1:6379> JSON.GET k1
"[[],[\"a\"]]"

127.0.0.1:6379> JSON.SET k2 . '[[], ["a"], ["a", "b"]]'
OK
127.0.0.1:6379> JSON.ARRPOP k2 . 0
"[]"
127.0.0.1:6379> JSON.GET k2
"[[\"a\"],[\"a\",\"b\"]]"

Replies

RESP2

  • If the path is enhanced syntax:
    • Array reply: Array of bulk strings representing popped values at each path.
    • Nil reply: For each path where the value is an empty array or not an array.
  • If the path is restricted syntax:
  • Simple error reply:
    • 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 bulk strings representing popped values at each path.
    • Null reply: For each path where the value is an empty array or not an array.
  • If the path is restricted syntax:
  • Simple error reply:
    • if the value at the path is not an array (only for restricted syntax).