JSON.ARRLEN

Usage:
JSON.ARRLEN key [ path ]
Complexity:
O(N) where N is the number of json arrays matched at the path.
Module:
valkey-json
Since module version:
1.0.0
ACL Categories:
@read, @fast, @json

Get length of the array at the path.

Examples

Enhanced path syntax:

127.0.0.1:6379> JSON.SET k1 . '[[], [\"a\"], [\"a\", \"b\"], [\"a\", \"b\", \"c\"]]'
(error) SYNTAXERR Failed to parse JSON string due to syntax error
127.0.0.1:6379> JSON.SET k1 . '[[], ["a"], ["a", "b"], ["a", "b", "c"]]'
OK
127.0.0.1:6379> JSON.ARRLEN k1 $[*]
1) (integer) 0
2) (integer) 1
3) (integer) 2
4) (integer) 3

127.0.0.1:6379> JSON.SET k2 . '[[], "a", ["a", "b"], ["a", "b", "c"], 4]'
OK
127.0.0.1:6379> JSON.ARRLEN k2 $[*]
1) (integer) 0
2) (nil)
3) (integer) 2
4) (integer) 3
5) (nil)
127.0.0.1:6379> JSON.SET k1 . '[[], ["a"], ["a", "b"], ["a", "b", "c"]]'
OK
127.0.0.1:6379> JSON.ARRLEN k1 [*]
(integer) 0
127.0.0.1:6379> JSON.ARRLEN k1 $[3]
1) (integer) 3

127.0.0.1:6379> JSON.SET k2 . '[[], "a", ["a", "b"], ["a", "b", "c"], 4]'
OK
127.0.0.1:6379> JSON.ARRLEN k2 [*]
(integer) 0
127.0.0.1:6379> JSON.ARRLEN k2 $[1]
1) (nil)
127.0.0.1:6379> JSON.ARRLEN k2 $[2]
1) (integer) 2

RESP2 Reply

  • If the path is enhanced syntax:

    • Array reply: Array of integers representing the array length at each path.

    • Nil reply: For each path where the value is not an array.

    • Nil reply: If the document key does not exist.

  • If the path is restricted syntax:

  • Simple error reply:

    • if the path does not exist.

    • if the value at the path is not an array (only for restricted syntax).

RESP3 Reply

  • If the path is enhanced syntax:

    • Array reply: Array of integers representing the array length at each path.

    • Null reply: For each path where the value is not an array.

    • Null reply: If the document key does not exist.

  • If the path is restricted syntax:

  • Simple error reply:

    • if the path does not exist.

    • if the value at the path is not an array (only for restricted syntax).