{
  "schema_version": 2,
  "id": "commands/json.set",
  "title": "JSON.SET",
  "url": "https://redis.io/docs/latest/commands/json.set/",
  "summary": "Sets or updates the JSON value at a 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": "adebc7150a2f4efa1274d8fd27cae92d491c27a783feb25f15f367647db18ca4",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "Set or replace the value at each location resolved by `path`.\n\nIf the key does not exist, a new JSON document can be created only by setting the root path (`$` or `.`).\n\n`JSON.SET` can also create new object members when the parent object exists.\n\n[Examples](#examples)"
    },
    {
      "id": "required-arguments",
      "title": "Required arguments",
      "role": "content",
      "text": "<details open><summary><code>key</code></summary> \n\nis a new key to create or an existing JSON key to modify.\n</details>\n\n<details open><summary><code>path</code></summary> \n\nA JSONPath expression that resolves to zero or more locations within the JSON document.\n\n- The root of the document is specified as `$` or `.`.\n- If `path` resolves to one or more existing locations, the value at each matched location is replaced with `value`.\n- If the final token of `path` is a non-existing object member and the parent location exists and is an object, the member is created and set to `value`.\n- If any intermediate path element does not exist, the path cannot be created, and the command returns nil.\n\nOptional arguments `NX` and `XX` modify this behavior for both new keys and existing JSON keys.\n</details>\n\n<details open><summary><code>value</code></summary> \n\nA valid JSON value to set at the specified path.\n\nThe value can be a scalar (string, number, boolean, or null) or a compound value such as an object or array.\n</details>"
    },
    {
      "id": "optional-arguments",
      "title": "Optional arguments",
      "role": "parameters",
      "text": "<details open><summary><code>NX</code></summary> \n\nSets the value only if `path` has no matches.\n</details>\n\n<details open><summary><code>XX</code></summary> \n\nSets the value only if `path` has one or more matches.\n</details>\n\n<details open><summary><code>FPHA <FP16 | BF16 | FP32 | FP64></code></summary>\n\nForce floating point homogeneous arrays (FPHAs) to use a specified FP type. Added in Redis 8.8.\n\nThe available types offer a trade-off between precision and memory footprint. FP64 (64-bit) and FP32 (32-bit) provide higher precision for scientific and general computing workloads. BF16 and FP16 (both 16-bit) use half the memory of FP32 and require less memory, making them well suited for AI training and inference. A common strategy is to store and compute in BF16/FP16 for speed while accumulating results in FP32 to maintain accuracy.\n\nSince JSON's numeric representation is textual, Redis cannot always infer the best FP type to use for FPHAs (for example, for vector embeddings). If your JSON was generated from an array of FP values with a given FP type, you should pass this type here.\n\nIf at least one of the specified values within the given FPHA doesn’t fit into the type specified (an overflow situation), the command will issue\na \"`value out of range`\" error.\n</details>"
    },
    {
      "id": "examples",
      "title": "Examples",
      "role": "example",
      "text": "<details open>\n<summary><b>Replace an existing value</b></summary>\n\n\nredis> JSON.SET doc $ '{\"a\":2}'\nOK\nredis> JSON.SET doc $.a '3'\nOK\nredis> JSON.GET doc $\n\"[{\\\"a\\\":3}]\"\n\n</details>\n\n<details open>\n<summary><b>Add a new value</b></summary>\n\n\nredis> JSON.SET doc $ '{\"a\":2}'\nOK\nredis> JSON.SET doc $.b '8'\nOK\nredis> JSON.GET doc $\n\"[{\\\"a\\\":2,\\\"b\\\":8}]\"\n\n</details>\n\n<details open>\n<summary><b>Add a new value with FPHA</b></summary>\n\n\nredis> JSON.SET doc $ '[[1,2,3,4e3],[5,6.0,7,8]]' FPHA FP16\nOK\nredis> JSON.GET doc $\n\"[[[1.0,2.0,3.0,4000.0],[5.0,6.0,7.0,8.0]]]\"\n\n</details>\n\n<details open>\n<summary><b>Update multiple matches</b></summary>\n\n\nredis> JSON.SET doc $ '{\"f1\": {\"a\":1}, \"f2\":{\"a\":2}}'\nOK\nredis> JSON.SET doc $..a 3\nOK\nredis> JSON.GET doc\n\"{\\\"f1\\\":{\\\"a\\\":3},\\\"f2\\\":{\\\"a\\\":3}}\"\n\n</details>\n\n<details open>\n<summary><b>path does not exist and cannot be created</b></summary>\n\n\nredis> JSON.SET doc $ 1\nOK\nredis> JSON.SET doc $.x.y 2\n(nil)\n\n</details>\n\n<details open>\n<summary><b>XX condition unmet</b></summary>\n\n\nredis> JSON.SET nonexistentkey $ 5 XX\n(nil)\nredis> JSON.GET nonexistentkey\n(nil)\n\n</details>\n\n<details open>\n<summary><b>key does not exist and path is not root</b></summary>\n\n\nredis> JSON.SET nonexistentkey $.x 5\n(error) ERR new objects must be created at the root\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\nOne of the following:\n* [Simple string reply](https://redis.io/docs/latest/develop/reference/protocol-spec#simple-strings): `OK` if executed correctly.\n* [Null reply](https://redis.io/docs/latest/develop/reference/protocol-spec#nulls): if `key` exists but `path` does not exist and cannot be created, or if an `NX` or `XX` condition is unmet.\n* [Simple error reply](https://redis.io/docs/latest/develop/reference/protocol-spec#simple-errors): `(error) expected ...` - if the value is invalid.\n* [Simple error reply](https://redis.io/docs/latest/develop/reference/protocol-spec#simple-errors): `(error) Error occurred on position ... expected ...` - if the path is invalid.\n* [Simple error reply](https://redis.io/docs/latest/develop/reference/protocol-spec#simple-errors): `(error) ERR new objects must be created at the root` - if `key` does not exist and `path` is not root (`$` or `.`).\n* [Simple error reply](https://redis.io/docs/latest/develop/reference/protocol-spec#simple-errors): `(error) ERR wrong static path` - if a dynamic path expression has no matching locations.\n* [Simple error reply](https://redis.io/docs/latest/develop/reference/protocol-spec#simple-errors): `(error) ERR index out of bounds` - if the path refers to an array index outside the array bounds.\n* [Simple error reply](https://redis.io/docs/latest/develop/reference/protocol-spec#simple-errors): `(error) value out of range for ...` - if one or more values of a FP array are out of range for the given type.\n\n**RESP3:**\n\nOne of the following:\n* [Simple string reply](https://redis.io/docs/latest/develop/reference/protocol-spec#simple-strings): `OK` if executed correctly.\n* [Null reply](https://redis.io/docs/latest/develop/reference/protocol-spec#nulls): if `key` exists but `path` does not exist and cannot be created, or if an `NX` or `XX` condition is unmet.\n* [Simple error reply](https://redis.io/docs/latest/develop/reference/protocol-spec#simple-errors): `(error) expected ...` - if the value is invalid.\n* [Simple error reply](https://redis.io/docs/latest/develop/reference/protocol-spec#simple-errors): `(error) Error occurred on position ... expected ...` - if the path is invalid.\n* [Simple error reply](https://redis.io/docs/latest/develop/reference/protocol-spec#simple-errors): `(error) ERR new objects must be created at the root` - if `key` does not exist and `path` is not root (`$` or `.`).\n* [Simple error reply](https://redis.io/docs/latest/develop/reference/protocol-spec#simple-errors): `(error) ERR wrong static path` - if a dynamic path expression has no matching locations.\n* [Simple error reply](https://redis.io/docs/latest/develop/reference/protocol-spec#simple-errors): `(error) ERR index out of bounds` - if the path refers to an array index outside the array bounds.\n* [Simple error reply](https://redis.io/docs/latest/develop/reference/protocol-spec#simple-errors): `(error) value out of range for ...` - if one or more values of a FP array are out of range for the given type."
    },
    {
      "id": "see-also",
      "title": "See also",
      "role": "related",
      "text": "[`JSON.GET`](https://redis.io/docs/latest/commands/json.get) | [`JSON.MGET`](https://redis.io/docs/latest/commands/json.mget)"
    },
    {
      "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": []
}
