Skip to main content
Use JSON.SET to set a JSON value at a path inside a document, creating the key when it does not exist. The value is JSON text; the Upstash SDK helpers serialize native objects for you. With the root path ($) the whole document is replaced, which is also how a new document is created. For a nested path the parent must already exist: the command adds one missing child to an existing object or appends to an existing array, but it does not create intermediate levels along the way. NX writes only when the path does not exist yet and XX only when it does, which makes conditional updates atomic. When the path is a JSONPath that matches several places, every match is updated in the same call, so a single command can update all elements of an array.

Syntax

Arguments

Important points

  • Raw TCP examples pass JSON values as valid JSON text. Typed Upstash SDK helpers serialize native objects and values for you.
  • Paths beginning with $ use JSONPath and can match multiple values, so many JSON commands return an array of per-match results.

Response

The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below.
Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply.

Examples

TCP examples use the TLS REDIS_URL from the Upstash console. REST examples use UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN.