JSON.ARRINDEX key path value [ start [stop]]

Available in: Redis Stack

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

[] 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)