JSON.CLEAR

Syntax

  1. JSON.CLEAR key [path]

Time complexity: O(N) when path is evaluated to a single value where N is the size of the values, O(N) when path is evaluated to multiple values, where N is the size of the key

ACL categories: @json

Clear container values (arrays/objects) and set numeric values to 0

Examples

Required arguments

key

is key to parse.

Optional arguments

path

is JSONPath to specify. Default is root $. Nonexisting paths are ignored.

Return

JSON.CLEAR returns an integer reply specified as the number of values cleared. For more information about replies, see Redis serialization protocol specification.

JSON.CLEAR - 图1Note

Already cleared values are ignored for empty containers and zero numbers.

Examples

Clear container values and set numeric values to 0

Create a JSON document.

  1. dragonfly> JSON.SET doc $ '{"obj":{"a":1, "b":2}, "arr":[1,2,3], "str": "foo", "bool": true, "int": 42, "float": 3.14}'
  2. OK

Clear all container values. This returns the number of objects with cleared values.

  1. dragonfly> JSON.CLEAR doc $.*
  2. (integer) 4

Get the updated document. Note that numeric values have been set to 0.

  1. dragonfly> JSON.GET doc $
  2. "[{\"obj\":{},\"arr\":[],\"str\":\"foo\",\"bool\":true,\"int\":0,\"float\":0}]"

See also

JSON.ARRINDEX | JSON.ARRINSERT