JSON.TOGGLE

JSON.TOGGLE key path
Available in:
Redis Open Source / JSON 2.0.0
Time complexity:
O(1) when path is evaluated to a single value, O(N) when path is evaluated to multiple values, where N is the size of the key
ACL categories:
@json, @write, @slow,
Compatibility:
Redis Enterprise and Redis Cloud compatibility

Toggle a Boolean value stored at path

Examples

Required arguments

key

is key to modify.

Optional arguments

path

is JSONPath to specify. Default is root $.

Examples

Toggle a Boolean value stored at path

Create a JSON document.

redis> JSON.SET doc $ '{"bool": true}'
OK

Toggle the Boolean value.

redis> JSON.TOGGLE doc $.bool
1) (integer) 0

Get the updated document.

redis> JSON.GET doc $
"[{\"bool\":false}]"

Toggle the Boolean value.

redis> JSON.TOGGLE doc $.bool
1) (integer) 1

Get the updated document.

redis> JSON.GET doc $
"[{\"bool\":true}]"

Redis Enterprise and Redis Cloud compatibility

Redis
Enterprise
Redis
Cloud
Notes
✅ Supported
✅ Flexible & Annual
✅ Free & Fixed

Return information

With $-based path argument: Array reply of integer replies or null replies, where each element is the new value (0 if false or 1 if true), or null if the matching value is not Boolean.

With .-based path argument: Integer reply representing the new value (0 if false or 1 if true), or null reply if the matching value is not Boolean.

See also

JSON.SET | JSON.GET

RATE THIS PAGE
Back to top ↑