Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

JSON.ARRINDEX

Focus mode
JSON.ARRINDEX - Amazon MemoryDB

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).

Syntax

JSON.ARRINDEX <key> <path> <json-scalar> [start [end]]
  • key (required) – key of JSON document type

  • path (required) – a JSON path

  • json-scalar (required) – scalar value to search for; JSON scalar refers to values that are not objects or arrays. i.e., String, number, boolean and null are scalar values.

  • start (optional) – start index, inclusive. Defaults to 0 if not provided.

  • end (optional) – end index, exclusive. Defaults to 0 if not provided, which means the last element is included. 0 or -1 means the last element is included.

Return

If the path is enhanced syntax:

  • 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.

  • If a value is not an array, its corresponding return value is null.

If the path is restricted syntax:

  • Integer, the index of matching element, or -1 if not found.

  • WRONGTYPE error if the value at the path is not an array.

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
PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.