{
  "schema_version": 2,
  "id": "commands/json.arrinsert",
  "title": "JSON.ARRINSERT",
  "url": "https://redis.io/docs/latest/commands/json.arrinsert/",
  "summary": "Inserts the JSON scalar(s) value at the specified index in the array at path",
  "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": "6278125fa2e7340a0673c7d4dbc8fcfa438b5c755b3ea72da7b4e74db85b0046",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "Insert the `json` values into the array at `path` before the `index` (shifts to the right)\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>\n\n<details open><summary><code>value</code></summary> \n\nis one or more values to insert in one or more arrays. \n\n> [!NOTE] About using strings with JSON commands\n> To specify a string as an array value to insert, wrap the quoted string with an additional set of single quotes. Example: `'\"silver\"'`. For more detailed use, see [Examples](#examples).\n</details>\n\n<details open><summary><code>index</code></summary> \n\nis position in the array where you want to insert a value. The index must be in the array's range. Inserting at `index` 0 prepends to the array. Negative index values start from the end of the array.\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>"
    },
    {
      "id": "examples",
      "title": "Examples",
      "role": "example",
      "text": "<details open>\n<summary><b>Add new colors to a specific place in a list of product colors</b></summary>\n\nCreate a document for noise-cancelling headphones in black and silver colors.\n\n\nredis> JSON.SET item:1 $ '{\"name\":\"Noise-cancelling Bluetooth headphones\",\"description\":\"Wireless Bluetooth headphones with noise-cancelling technology\",\"connection\":{\"wireless\":true,\"type\":\"Bluetooth\"},\"price\":99.98,\"stock\":25,\"colors\":[\"black\",\"silver\"]}'\nOK\n\n\nAdd color `blue` to the end of the `colors` array. `JSON.ARRAPEND` returns the array's new size.\n\n\nredis> JSON.ARRAPPEND item:1 $.colors '\"blue\"'\n1) (integer) 3\n\n\nReturn the new length of the `colors` array.\n\n\nredis> JSON.GET item:1\n\"{\\\"name\\\":\\\"Noise-cancelling Bluetooth headphones\\\",\\\"description\\\":\\\"Wireless Bluetooth headphones with noise-cancelling technology\\\",\\\"connection\\\":{\\\"wireless\\\":true,\\\"type\\\":\\\"Bluetooth\\\"},\\\"price\\\":99.98,\\\"stock\\\":25,\\\"colors\\\":[\\\"black\\\",\\\"silver\\\",\\\"blue\\\"]}\"\n\n\nGet the list of colors for the product.\n\n\nredis> JSON.GET item:1 '$.colors[*]'\n\"[\\\"black\\\",\\\"silver\\\",\\\"blue\\\"]\"\n\n\nInsert two more colors after the second color. You now have five colors.\n\n\nredis> JSON.ARRINSERT item:1 $.colors 2 '\"yellow\"' '\"gold\"'\n1) (integer) 5\n\n\nGet the updated list of colors.\n\n\nredis> JSON.GET item:1 $.colors\n\"[[\\\"black\\\",\\\"silver\\\",\\\"yellow\\\",\\\"gold\\\",\\\"blue\\\"]]\"\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.ARRAPPEND`](https://redis.io/docs/latest/commands/json.arrappend) | [`JSON.ARRINDEX`](https://redis.io/docs/latest/commands/json.arrindex)"
    },
    {
      "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": []
}
