{
  "schema_version": 2,
  "id": "commands/json.arrtrim",
  "title": "JSON.ARRTRIM",
  "url": "https://redis.io/docs/latest/commands/json.arrtrim/",
  "summary": "Trims the array at path to contain only the specified inclusive range of indices from start to stop",
  "since": "1.0.0",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-09-18T09:47:58+01:00",
  "page_type": "content",
  "content_hash": "63d023c36be087d1afd402333cf83e4cbf8d80eee9ef8d7ef242e7fa84fdde4d",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "Trim an array so that it contains only the specified inclusive range of elements\n\n[Examples](#examples)"
    },
    {
      "id": "required-arguments",
      "title": "Required arguments",
      "role": "content",
      "text": "<details open><summary><code>key</code></summary> \n\nis key to modify.\n</details>"
    },
    {
      "id": "optional-arguments",
      "title": "Optional arguments",
      "role": "parameters",
      "text": "<details open><summary><code>path</code></summary> \n\nis JSONPath to specify. Default is root `$`.\n</details>\n\n<details open><summary><code>start</code></summary> \n\nis index of the first element to keep (previous elements are trimmed). Default is 0. \n</details>\n\n<details open><summary><code>stop</code></summary> \n\nis the index of the last element to keep (following elements are trimmed), including the last element. Default is 0. Negative values are interpreted as starting from the end.\n</details>\n\n> [!NOTE] About out-of-range indexes\n> JSON.ARRTRIM is extremely forgiving, and using it with out-of-range indexes does not produce an error. Note a few differences between how RedisJSON v2.0 and legacy versions handle out-of-range indexes.\n>\n> Behavior as of RedisJSON v2.0:\n>\n> * If `start` is larger than the array's size or `start` > `stop`, returns 0 and an empty array. \n> * If `start` is < 0, then start from the end of the array.\n> * If `stop` is larger than the end of the array, it is treated like the last element."
    },
    {
      "id": "examples",
      "title": "Examples",
      "role": "example",
      "text": "<details open>\n<summary><b>Trim an array to a specific set of values</b></summary>\n\nCreate two headphone products with maximum sound levels.\n\n\nredis> JSON.SET key $\n\"[{\\\"name\\\":\\\"Healthy headphones\\\",\\\"description\\\":\\\"Wireless Bluetooth headphones with noise-cancelling technology\\\",\\\"connection\\\":{\\\"wireless\\\":true,\\\"type\\\":\\\"Bluetooth\\\"},\\\"price\\\":99.98,\\\"stock\\\":25,\\\"colors\\\":[\\\"black\\\",\\\"silver\\\"],\\\"max_level\\\":[60,70,80]},{\\\"name\\\":\\\"Noisy headphones\\\",\\\"description\\\":\\\"Wireless Bluetooth headphones with noise-cancelling technology\\\",\\\"connection\\\":{\\\"wireless\\\":true,\\\"type\\\":\\\"Bluetooth\\\"},\\\"price\\\":99.98,\\\"stock\\\":25,\\\"colors\\\":[\\\"black\\\",\\\"silver\\\"],\\\"max_level\\\":[85,90,100,120]}]\"\nOK\n\n\nAdd new sound level values to the second product.\n\n\nredis> JSON.ARRAPPEND key $.[1].max_level 140 160 180 200 220 240 260 280\n1) (integer) 12\n\n\nGet the updated array.\n\n\nredis> JSON.GET key $.[1].max_level\n\"[[85,90,100,120,140,160,180,200,220,240,260,280]]\"\n\n\nKeep only the values between the fifth and the ninth element, inclusive of that last element.\n\n\nredis> JSON.ARRTRIM key $.[1].max_level 4 8\n1) (integer) 5\n\n\nGet the updated array.\n\n\nredis> JSON.GET key $.[1].max_level\n\"[[140,160,180,200,220]]\"\n\n</details>"
    },
    {
      "id": "redis-software-and-redis-cloud-compatibility",
      "title": "Redis Software and Redis Cloud compatibility",
      "role": "content",
      "text": "| Redis<br />Software | Redis<br />Cloud | <span style=\"min-width: 9em; display: table-cell\">Notes</span> |\n|:----------------------|:-----------------|:------|\n| <span title=\"Supported\">&#x2705; Supported</span><br /> | <span title=\"Supported\">&#x2705; Flexible & Annual</span><br /><span title=\"Supported\">&#x2705; Free & Fixed</nobr></span> |  |"
    },
    {
      "id": "return-information",
      "title": "Return information",
      "role": "returns",
      "text": "**RESP2:**\n\nWith `$`-based path argument: [Array reply](https://redis.io/docs/latest/develop/reference/protocol-spec#arrays) of [integer replies](https://redis.io/docs/latest/develop/reference/protocol-spec#integers) or [null replies](https://redis.io/docs/latest/develop/reference/protocol-spec#nulls), where each element is the array's new size, or `null` if the matching value is not an array.\n\nWith `.`-based path argument: [Integer reply](https://redis.io/docs/latest/develop/reference/protocol-spec#integers) representing the array's new size, or [null reply](https://redis.io/docs/latest/develop/reference/protocol-spec#nulls) if the matching value is not an array.\n\n**RESP3:**\n\nWith `$`-based path argument (default): [Array reply](https://redis.io/docs/latest/develop/reference/protocol-spec#arrays) of [integer replies](https://redis.io/docs/latest/develop/reference/protocol-spec#integers) or [null replies](https://redis.io/docs/latest/develop/reference/protocol-spec#nulls), where each element is the array's new size, or `null` if the matching value is not an array.\n\nWith `.`-based path argument: [Integer reply](https://redis.io/docs/latest/develop/reference/protocol-spec#integers) representing the array's new size, or [null reply](https://redis.io/docs/latest/develop/reference/protocol-spec#nulls) if the matching value is not an array."
    },
    {
      "id": "see-also",
      "title": "See also",
      "role": "related",
      "text": "[`JSON.ARRINDEX`](https://redis.io/docs/latest/commands/json.arrindex) | [`JSON.ARRINSERT`](https://redis.io/docs/latest/commands/json.arrinsert)"
    },
    {
      "id": "related-topics",
      "title": "Related topics",
      "role": "related",
      "text": "* [RedisJSON](https://redis.io/docs/latest/develop/data-types/json)\n* [Index and search JSON documents](https://redis.io/docs/latest/develop/ai/search-and-query/indexing)"
    }
  ],
  "examples": []
}
