Skip to main content
Searches for the first occurrence of a value in a JSON array and returns its index.

Usage

Arguments

key
string
required
The key containing the JSON document
path
string
required
JSONPath expression pointing to the array to search
value
TValue
required
The value to search for in the array
start
number
Optional start index for the search (inclusive). Defaults to 0. Negative values count from the end of the array.
stop
number
Optional stop index for the search (exclusive). Defaults to the end of the array. Negative values count from the end of the array.

Response

result
(number | null)[]
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 -1 if the value is not found in the array
  • Returns null if the path doesn’t exist or doesn’t point to an array
  • Object comparison is based on exact JSON match

See Also