JSON.TOGGLE

Usage:
JSON.TOGGLE key [ path ]
Complexity:
O(N) where N is the number of json boolean values matched by the path.
Module:
valkey-json
Since module version:
1.0.0
ACL Categories:
@write, @fast, @json

Toggle boolean values between true and false at the path.

Examples

Enhanced path syntax:

127.0.0.1:6379> JSON.SET k1 . '{"a":true, "b":false, "c":1, "d":null, "e":"foo", "f":[], "g":{}}'
OK
127.0.0.1:6379> JSON.TOGGLE k1 $.*
1) (integer) 0
2) (integer) 1
3) (nil)
4) (nil)
5) (nil)
6) (nil)
7) (nil)
127.0.0.1:6379> JSON.TOGGLE k1 $.*
1) (integer) 1
2) (integer) 0
3) (nil)
4) (nil)
5) (nil)
6) (nil)
7) (nil)

Restricted path syntax:

127.0.0.1:6379> JSON.SET k1 . true
OK
127.0.0.1:6379> JSON.TOGGLE k1
"false"
127.0.0.1:6379> JSON.TOGGLE k1
"true"

127.0.0.1:6379> JSON.SET k2 . '{"isAvailable": false}'
OK
127.0.0.1:6379> JSON.TOGGLE k2 .isAvailable
"true"
127.0.0.1:6379> JSON.TOGGLE k2 .isAvailable
"false"

RESP2 Reply

  • If the path is enhanced syntax:

    • Array reply: Array of integers (0 for false, 1 for true) representing the resulting boolean value at each path.

    • Nil reply: For each path where the value is not a boolean.

  • If the path is restricted syntax:

  • Simple error reply:

    • if the document key does not exist.

    • if the value at the path is not a boolean (only for restricted syntax).

RESP3 Reply

  • If the path is enhanced syntax:

    • Array reply: Array of integers (0 for false, 1 for true) representing the resulting boolean value at each path.

    • Null reply: For each path where the value is not a boolean.

  • If the path is restricted syntax:

  • Simple error reply:

    • if the document key does not exist.

    • if the value at the path is not a boolean (only for restricted syntax).