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

Focus mode
JSON.ARRINSERT - Amazon MemoryDB

Insert one or more values into the array values at path before the index.

Syntax

JSON.ARRINSERT <key> <path> <index> <json> [json ...]
  • key (required) – key of JSON document type

  • path (required) – a JSON path

  • index (required) – array index before which values are inserted.

  • json (required) – JSON value to be appended to the array

Return

If the path is enhanced syntax:

  • Array of integers, representing the new length of the array at each path.

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

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

  • OUTOFBOUNDARIES error if the index argument is out of bounds.

If the path is restricted syntax:

  • Integer, the new length of the array.

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

  • OUTOFBOUNDARIES error if the index argument is out of bounds.

Examples

Enhanced path syntax:

127.0.0.1:6379> JSON.SET k1 . '[[], ["a"], ["a", "b"]]' OK 127.0.0.1:6379> JSON.ARRINSERT k1 $[*] 0 '"c"' 1) (integer) 1 2) (integer) 2 3) (integer) 3 127.0.0.1:6379> JSON.GET k1 "[[\"c\"],[\"c\",\"a\"],[\"c\",\"a\",\"b\"]]"

Restricted path syntax:

127.0.0.1:6379> JSON.SET k1 . '[[], ["a"], ["a", "b"]]' OK 127.0.0.1:6379> JSON.ARRINSERT k1 . 0 '"c"' (integer) 4 127.0.0.1:6379> JSON.GET k1 "[\"c\",[],[\"a\"],[\"a\",\"b\"]]"
PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.