StaticarrappendAppends one or more values to the JSON array at the specified path within the JSON
document stored at key.
A batch to add commands to.
The key of the JSON document.
The path within the JSON document.
The JSON values to be appended to the array.
JSON string values must be wrapped with quotes. For example, to append "foo", pass "\"foo\"".
Command Response -
$):
Returns an array with a list of integers for every possible path,
indicating the new length of the array, or null for JSON values matching
the path that are not an array. If path does not exist, an empty array
will be returned.$):
Returns an integer representing the new length of the array. If multiple paths are
matched, returns the length of the first modified array. If path doesn't
exist or the value at path is not an array, an error is raised.key doesn't exist, an error is raised.StaticarrindexSearches for the first occurrence of a scalar JSON value in the arrays at the path.
Out of range errors are treated by rounding the index to the array's start and end. If start>end, return -1` (not found).
A batch to add commands to.
The key of the JSON document.
The path within the JSON document.
The scalar value to search for.
Optionaloptions: { end?: number; start: number }(Optional) Additional parameters:
start: The start index, inclusive. Default to 0 if not provided.end: The end index, exclusive. Default to 0 if not provided.
0 or -1 means the last element is included.
Command Response -$):
Returns an array with a list of integers for every possible path,
indicating the index of the matching element. The value is -1 if not found.
If a value is not an array, its corresponding return value is null.$):
Returns an integer representing the index of matching element, or -1 if
not found. If the value at the path is not an array, an error is raised.StaticarrinsertInserts one or more values into the array at the specified path within the JSON
document stored at key, before the given index.
A batch to add commands to.
The key of the JSON document.
The path within the JSON document.
The array index before which values are inserted.
The JSON values to be inserted into the array.
JSON string values must be wrapped with quotes. For example, to insert "foo", pass "\"foo\"".
Command Response -
$):
Returns an array with a list of integers for every possible path,
indicating the new length of the array, or null for JSON values matching
the path that are not an array. If path does not exist, an empty array
will be returned.$):
Returns an integer representing the new length of the array. If multiple paths are
matched, returns the length of the first modified array. If path doesn't
exist or the value at path is not an array, an error is raised.key doesn't exist, an error is raised.StaticarrlenRetrieves the length of the array at the specified path within the JSON document stored at key.
A batch to add commands to.
The key of the JSON document.
Optionaloptions: { path: GlideString }(Optional) Additional parameters:
path: The path within the JSON document. Defaults to the root (".") if not specified.Command Response -
$):
Returns an array with a list of integers for every possible path,
indicating the length of the array, or null for JSON values matching
the path that are not an array. If path does not exist, an empty array
will be returned.$):
Returns an integer representing the length of the array. If multiple paths are
matched, returns the length of the first matching array. If path doesn't
exist or the value at path is not an array, an error is raised.key doesn't exist, an error is raised.StaticarrpopPops an element from the array located at path in the JSON document stored at key.
A batch to add commands to.
The key of the JSON document.
Optionaloptions: JsonArrPopOptions(Optional) See JsonArrPopOptions.
Command Response -
$):
Returns an array with a strings for every possible path, representing the popped JSON
values, or null for JSON values matching the path that are not an array
or an empty array.$):
Returns a string representing the popped JSON value, or null if the
array at path is empty. If multiple paths are matched, the value from
the first matching array that is not empty is returned. If path doesn't
exist or the value at path is not an array, an error is raised.key doesn't exist, an error is raised.StaticarrtrimTrims an array at the specified path within the JSON document stored at key so that it becomes a subarray [start, end], both inclusive.
If start < 0, it is treated as 0.
If end >= size (size of the array), it is treated as size-1.
If start >= size or start > end, the array is emptied and 0 is returned.
A batch to add commands to.
The key of the JSON document.
The path within the JSON document.
The start index, inclusive.
The end index, inclusive.
Command Response -
- For JSONPath (path starts with $):
- Returns a list of integer replies for every possible path, indicating the new length of the array,
or null for JSON values matching the path that are not an array.
- If the array is empty, its corresponding return value is 0.
- If path doesn't exist, an empty array will be returned.
- If an index argument is out of bounds, an error is raised.
- For legacy path (path doesn't start with $):
- Returns an integer representing the new length of the array.
- If the array is empty, its corresponding return value is 0.
- If multiple paths match, the length of the first trimmed array match is returned.
- If path doesn't exist, or the value at path is not an array, an error is raised.
- If an index argument is out of bounds, an error is raised.
StaticclearClears arrays or objects at the specified JSON path in the document stored at key.
Numeric values are set to 0, boolean values are set to false, and string values are converted to empty strings.
A batch to add commands to.
The key of the JSON document.
Optionaloptions: { path: GlideString }(Optional) Additional parameters:
path: The JSON path to the arrays or objects to be cleared. Defaults to root if not provided.Command Response - The number of containers cleared, numeric values zeroed, and booleans toggled to false,
and string values converted to empty strings.
If path doesn't exist, or the value at path is already empty (e.g., an empty array, object, or string), 0 is returned.
If `key doesn't exist, an error is raised.
StaticdebugReports the number of fields at the specified path within the JSON document stored at key.
A batch to add commands to.
The key of the JSON document.
Optionaloptions: { path: GlideString }(Optional) Additional parameters:
path: The path within the JSON document, returns total number of fields if no path is given.Command Response -
- For JSONPath (path starts with $):
- Returns an array of numbers for every possible path, indicating the number of fields.
If path does not exist, an empty array will be returned.
- For legacy path (path doesn't start with $):
- Returns an integer representing the memory usage. If multiple paths are matched,
returns the data of the first matching object. If path doesn't exist, an error is raised.
- If key doesn't exist, returns null.
StaticdebugReports memory usage in bytes of a JSON object at the specified path within the JSON document stored at key.
A batch to add commands to.
The key of the JSON document.
Optionaloptions: { path: GlideString }(Optional) Additional parameters:
path: The path within the JSON document, returns total memory usage if no path is given.Command Response -
- For JSONPath (path starts with $):
- Returns an array of numbers for every possible path, indicating the memory usage.
If path does not exist, an empty array will be returned.
- For legacy path (path doesn't start with $):
- Returns an integer representing the memory usage. If multiple paths are matched,
returns the data of the first matching object. If path doesn't exist, an error is raised.
- If key doesn't exist, returns null.
StaticdelDeletes the JSON value at the specified path within the JSON document stored at key.
A batch to add commands to.
The key of the JSON document.
Optionaloptions: { path: GlideString }(Optional) Additional parameters:
path: If null, deletes the entire JSON document at key.Command Response - The number of elements removed. If key or path doesn't exist, returns 0.
StaticforgetDeletes the JSON value at the specified path within the JSON document stored at key. This command is
an alias of del.
A batch to add commands to.
The key of the JSON document.
Optionaloptions: { path: GlideString }(Optional) Additional parameters:
path: If null, deletes the entire JSON document at key.Command Response - The number of elements removed. If key or path doesn't exist, returns 0.
StaticgetRetrieves the JSON value at the specified paths stored at key.
A batch to add commands to.
The key of the JSON document.
Optionaloptions: JsonGetOptions(Optional) Additional parameters:
Command Response -
$):
key doesn't exist, returns null.$):
Returns a byte string representation of the value in path.
If path doesn't exist, an error is raised.
If key doesn't exist, returns null.paths are a mix of both JSONPath and legacy path, the command behaves as if all are JSONPath paths.StaticmgetRetrieves the JSON values at the specified path stored at multiple keys.
The keys of the JSON documents.
The path within the JSON documents.
Command Response -
$):
Returns a stringified JSON list replies for every possible path, or a string representation
of an empty array, if path doesn't exist.$):
Returns a string representation of the value in path. If path doesn't exist,
the corresponding array element will be null.key doesn't exist, the corresponding array element will be null.StaticnumincrbyIncrements or decrements the JSON value(s) at the specified path by number within the JSON document stored at key.
A batch to add commands to.
The key of the JSON document.
The path within the JSON document.
The number to increment or decrement by.
Command Response -
- For JSONPath (path starts with $):
- Returns a string representation of an array of strings, indicating the new values after incrementing for each matched path.
If a value is not a number, its corresponding return value will be null.
If path doesn't exist, a byte string representation of an empty array will be returned.
- For legacy path (path doesn't start with $):
- Returns a string representation of the resulting value after the increment or decrement.
If multiple paths match, the result of the last updated value is returned.
If the value at the path is not a number or path doesn't exist, an error is raised.
- If key does not exist, an error is raised.
- If the result is out of the range of 64-bit IEEE double, an error is raised.
StaticnummultbyMultiplies the JSON value(s) at the specified path by number within the JSON document stored at key.
A batch to add commands to.
The key of the JSON document.
The path within the JSON document.
The number to multiply by.
Command Response -
- For JSONPath (path starts with $):
- Returns a GlideString representation of an array of strings, indicating the new values after multiplication for each matched path.
If a value is not a number, its corresponding return value will be null.
If path doesn't exist, a byte string representation of an empty array will be returned.
- For legacy path (path doesn't start with $):
- Returns a GlideString representation of the resulting value after multiplication.
If multiple paths match, the result of the last updated value is returned.
If the value at the path is not a number or path doesn't exist, an error is raised.
- If key does not exist, an error is raised.
- If the result is out of the range of 64-bit IEEE double, an error is raised.
StaticobjkeysRetrieves key names in the object values at the specified path within the JSON document stored at key.
A batch to add commands to.
The key of the JSON document.
Optionaloptions: { path: GlideString }(Optional) Additional parameters:
path: The path within the JSON document where the key names will be retrieved. Defaults to root (".") if not provided.Command Response - ReturnTypeJson<GlideString[]>:
path starts with $):
path doesn't exist, an empty array is returned.path starts with .):
path doesn't exist, null is returned.key doesn't exist, null is returned.StaticobjlenRetrieves the number of key-value pairs in the object stored at the specified path within the JSON document stored at key.
A batch to add commands to.
The key of the JSON document.
Optionaloptions: { path: GlideString }(Optional) Additional parameters:
path: The path within the JSON document, Defaults to root (".") if not provided.Command Response - ReturnTypeJson
path starts with $):
null for JSON values matching the path that are not an object.path doesn't exist, an empty array will be returned.path doesn't starts with $):
path.path is not an object or if path doesn't exist, an error is raised.key doesn't exist, null is returned.StaticrespRetrieve the JSON value at the specified path within the JSON document stored at key.
The returning result is in the Valkey or Redis OSS Serialization Protocol (RESP).
A batch to add commands to.
The key of the JSON document.
Optionaloptions: { path: GlideString }(Optional) Additional parameters:
path: The path within the JSON document, defaults to root (".") if not provided.Command Response -
- For JSONPath (path starts with $):
- Returns an array of replies for every possible path, indicating the RESP form of the JSON value.
If path doesn't exist, returns an empty array.
- For legacy path (path doesn't start with $):
- Returns a single reply for the JSON value at the specified path, in its RESP form.
If multiple paths match, the value of the first JSON value match is returned. If path doesn't exist, an error is raised.
- If key doesn't exist, null is returned.
StaticsetSets the JSON value at the specified path stored at key.
A batch to add commands to.
The key of the JSON document.
Represents the path within the JSON document where the value will be set.
The key will be modified only if value is added as the last child in the specified path, or if the specified path acts as the parent of a new child being added.
The value to set at the specific path, in JSON formatted bytes or str.
Optionaloptions: { conditionalChange: ConditionalChange }(Optional) Additional parameters:
conditionalChange - Set the value only if the given condition is met (within the key or path).
Equivalent to [XX | NX] in the module API.Command Response - If the value is successfully set, returns "OK".
If value isn't set because of conditionalChange, returns null.
StaticstrappendAppends the specified value to the string stored at the specified path within the JSON document stored at key.
A batch to add commands to.
The key of the JSON document.
The value to append to the string. Must be wrapped with single quotes. For example, to append "foo", pass '"foo"'.
Optionaloptions: { path: GlideString }(Optional) Additional parameters:
path: The path within the JSON document, defaults to root (".") if not provided.Command Response -
- For JSONPath (path starts with $):
- Returns a list of integer replies for every possible path, indicating the length of the resulting string after appending value,
or None for JSON values matching the path that are not string.
- If key doesn't exist, an error is raised.
- For legacy path (path doesn't start with $):
- Returns the length of the resulting string after appending value to the string at path.
- If multiple paths match, the length of the last updated string is returned.
- If the JSON value at path is not a string of if path doesn't exist, an error is raised.
- If key doesn't exist, an error is raised.
StaticstrlenReturns the length of the JSON string value stored at the specified path within
the JSON document stored at key.
A batch to add commands to.
The key of the JSON document.
Optionaloptions: { path: GlideString }(Optional) Additional parameters:
path: The path within the JSON document, Defaults to root (".") if not provided.Command Response -
- For JSONPath (path starts with $):
- Returns a list of integer replies for every possible path, indicating the length of
the JSON string value, or null for JSON values matching the path that
are not string.
- For legacy path (path doesn't start with $):
- Returns the length of the JSON value at path or null if key doesn't exist.
- If multiple paths match, the length of the first matched string is returned.
- If the JSON value atpath is not a string or if path doesn't exist, an error is raised.
- If key doesn't exist, null is returned.
StatictoggleToggles a Boolean value stored at the specified path within the JSON document stored at key.
A batch to add commands to.
The key of the JSON document.
Optionaloptions: { path: GlideString }(Optional) Additional parameters:
path: The path within the JSON document. Defaults to the root (".") if not specified.Command Response - For JSONPath (path starts with $), returns a list of boolean replies for every possible path, with the toggled boolean value,
or null for JSON values matching the path that are not boolean.
path doesn't starts with $), returns the value of the toggled boolean in path.path doesn't exist or the value at path isn't a boolean, an error is raised.StatictypeReports the type of values at the given path.
A batch to add commands to.
The key of the JSON document.
Optionaloptions: { path: GlideString }(Optional) Additional parameters:
path: Defaults to root (".") if not provided.Command Response -
- For JSONPath (path starts with $):
- Returns an array of strings that represents the type of value at each path.
The type is one of "null", "boolean", "string", "number", "integer", "object" and "array".
- If a path does not exist, its corresponding return value is null.
- Empty array if the document key does not exist.
- For legacy path (path doesn't start with $):
- String that represents the type of the value.
- null if the document key does not exist.
- null if the JSON path is invalid or does not exist.
Batch implementation for JSON module. Batches allow the execution of a group of commands in a single step. See Batch and ClusterBatch.
Example