Usage
Arguments
The key containing the JSON document
JSONPath expression pointing to the array to search
The value to search for in the array
Optional start index for the search (inclusive). Defaults to
0. Negative values count from the end of the array.Optional stop index for the search (exclusive). Defaults to the end of the array. Negative values count from the end of the array.
Response
An array of integers representing the index of the first occurrence of the value at each matching path. Returns
-1 if the value is not found, or null if the path doesn’t exist or isn’t an array.Examples
Find value in array
Value not found
Search with start index
Search with start and stop indices
Search with negative indices
Search for objects in array
Search in multiple arrays (wildcard path)
Handle non-existent paths
JSONPath Syntax
$.array- Search in a top-level array$.nested.array- Search in a nested array$.items[0].tags- Search in array within array element$..array- Search in all matching arrays recursively$.users[*].roles- Search in arrays within each user
Notes
- Only the first occurrence within the search range is returned
- Negative indices count backwards from the end of the array
- The stop index is exclusive (not included in the search)
- Returns
-1if the value is not found in the array - Returns
nullif the path doesn’t exist or doesn’t point to an array - Object comparison is based on exact JSON match
See Also
- JSON.ARRAPPEND - Append values to array
- JSON.GET - Get JSON values
- Redis JSON.ARRINDEX documentation