JSON.ARRINDEX

Usage:
JSON.ARRINDEX key path json-scalar [ start ] [ end ]
Complexity:
O(N), where N is the length of the array.
Module:
valkey-json
Since module version:
1.0.0
ACL Categories:
@read, @fast, @json

Search for the first occurrence of a scalar JSON value in the arrays at the path.

  • Out of range errors are treated by rounding the index to the array's start and end.
  • If start > end, return -1 (not found).

Examples

Enhanced path syntax:

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

Restricted path syntax:

127.0.0.1:6379> JSON.SET k1 . '{"children": ["John", "Jack", "Tom", "Bob", "Mike"]}'
OK
127.0.0.1:6379> JSON.ARRINDEX k1 .children '"Tom"'
(integer) 2

RESP2 Reply

  • If the path is enhanced syntax:

    • Array reply: Array of integers. Each value is the index of the matching element in the array at the path. The value is -1 if not found.

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

  • If the path is restricted syntax:

    • Integer reply: The index of matching element, or -1 if not found.
  • 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. Each value is the index of the matching element in the array at the path. The value is -1 if not found.

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

  • If the path is restricted syntax:

    • Integer reply: The index of matching element, or -1 if not found.
  • Simple error reply:

    • if the path does not exist.

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