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

Focus mode
JSON.ARRTRIM - Amazon MemoryDB

Trim arrays at the path so that it becomes subarray [start, end], both inclusive.

  • If the array is empty, do nothing, return 0.

  • If start <0, treat it as 0.

  • If end >= size (size of the array), treat it as size-1.

  • If start >= size or start > end, empty the array and return 0.

Syntax

JSON.ARRINSERT <key> <path> <start> <end>
  • key (required) – key of JSON document type

  • path (required) – a JSON path

  • start (required) – start index, inclusive.

  • end (required) – end index, inclusive.

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 an index argument is out of bounds.

If the path is restricted syntax:

  • Integer, the new length of the array.

  • Null if the array is empty.

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

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

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.ARRTRIM k1 $[*] 0 1 1) (integer) 0 2) (integer) 1 3) (integer) 2 4) (integer) 2 127.0.0.1:6379> JSON.GET k1 "[[],[\"a\"],[\"a\",\"b\"],[\"a\",\"b\"]]"

Restricted path syntax:

127.0.0.1:6379> JSON.SET k1 . '{"children": ["John", "Jack", "Tom", "Bob", "Mike"]}' OK 127.0.0.1:6379> JSON.ARRTRIM k1 .children 0 1 (integer) 2 127.0.0.1:6379> JSON.GET k1 .children "[\"John\",\"Jack\"]"
PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.