JSON.ARRINDEX

Syntax
JSON.ARRINDEX key path value [start [stop]]
Available in:
Redis Stack / JSON 1.0.0
Time complexity:
O(N) when path is evaluated to a single value where N is the size of the array, O(N) when path is evaluated to multiple values, where N is the size of the key

Searches for the first occurrence of a scalar JSON value in an array.

The optional inclusive start (default 0) and exclusive stop (default 0, meaning that the last element is included) specify a slice of the array to search. Negative values are interpreted as starting from the end.

Note: out-of-range indexes round to the array's start and end. An inverse index range (such as the range from 1 to 0) will return unfound.

Return

Array reply of Integer reply - the first position in the array of each JSON value that matches the path, -1 if unfound in the array, or Null reply if the matching JSON value is not an array.

Examples

redis> JSON.SET doc $ '{"a":[1,2,3,2], "nested": {"a": [3,4]}}'
OK
redis> JSON.ARRINDEX doc $..a 2
1) (integer) 1
2) (integer) -1
redis> JSON.SET doc $ '{"a":[1,2,3,2], "nested": {"a": false}}'
OK
redis> JSON.ARRINDEX doc $..a 2
1) (integer) 1
2) (nil)

Feedback

If you've found issues on this page, or have suggestions for improvement, please submit a request to merge or open an issue in the repository.