JSON.TOGGLE - Amazon ElastiCache for Redis
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).


Toggles Boolean values between true and false at the path.


JSON.TOGGLE <key> [path]
  • key (required) – A Redis key of JSON document type.

  • path (optional) – A JSON path. Defaults to the root if not provided.


If the path is enhanced syntax:

  • Array of integers (0 - false, 1 - true) that represent the resulting Boolean value at each path.

  • If a value is a not a Boolean value, its corresponding return value is null.

  • NONEXISTENT if the document key does not exist.

If the path is restricted syntax:

  • String ("true"/"false") that represents the resulting Boolean value.

  • NONEXISTENT if the document key does not exist.

  • WRONGTYPE error if the value at the path is not a Boolean value.


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

Restricted path syntax:> JSON.SET k1 . true OK> JSON.TOGGLE k1 "false"> JSON.TOGGLE k1 "true"> JSON.SET k2 . '{"isAvailable": false}' OK> JSON.TOGGLE k2 .isAvailable "true"> JSON.TOGGLE k2 .isAvailable "false"