Skip to main content
Sets the JSON value at the specified path in the key. Creates the key if it doesn’t exist.

Usage

Arguments

key
string
required
The key to store the JSON document
path
string
required
JSONPath expression specifying where to set the value in the JSON document. Use $ to set the entire document.
value
TData
required
The JSON value to set. Can be a number, string, boolean, object, or array.
opts
object
Optional conditional set options

Response

result
'OK' | null
Returns "OK" if the value was set successfully, or null if the condition (NX/XX) was not met.

Examples

Set entire JSON document

Set specific field

Set nested value

Set array element

Conditional set - only if path doesn’t exist (NX)

Conditional set - only if path exists (XX)

JSONPath Syntax

  • $ - Root element (sets entire document)
  • $.field - Set a specific field
  • $.field[0] - Set array element at index
  • $.nested.field - Set nested field

See Also