content/commands/json.clear.md
Clear container values (arrays/objects) and set numeric values to 0
is key to parse.
</details>is JSONPath to specify. Default is root $. Nonexisting paths are ignored.
{{% alert title="Note" color="warning" %}}
Already cleared values are ignored for empty containers and zero numbers.
{{% /alert %}}
Create a JSON document.
{{< highlight bash >}} redis> JSON.SET doc $ '{"obj":{"a":1, "b":2}, "arr":[1,2,3], "str": "foo", "bool": true, "int": 42, "float": 3.14}' OK {{< / highlight >}}
Clear all container values. This returns the number of objects with cleared values.
{{< highlight bash >}} redis> JSON.CLEAR doc $.* (integer) 4 {{< / highlight >}}
Get the updated document. Note that numeric values have been set to 0.
{{< highlight bash >}} redis> JSON.GET doc $ "[{"obj":{},"arr":[],"str":"foo","bool":true,"int":0,"float":0}]" {{< / highlight >}}
</details>| Redis Software | Redis Cloud | <span style="min-width: 9em; display: table-cell">Notes</span> | |:----------------------|:-----------------|:------| | <span title="Supported">✅ Supported</span> | <span title="Supported">✅ Flexible & Annual</span> <span title="Supported">✅ Free & Fixed</nobr></span> | |
{{< multitabs id="json-clear-return-info" tab1="RESP2" tab2="RESP3" >}}
[Integer reply]({{< relref "/develop/reference/protocol-spec#integers" >}}): the number of matching JSON arrays and objects cleared plus the number of matching JSON numerical values zeroed.
-tab-sep-
[Integer reply]({{< relref "/develop/reference/protocol-spec#integers" >}}): the number of matching JSON arrays and objects cleared plus the number of matching JSON numerical values zeroed.
{{< /multitabs >}}
[JSON.ARRINDEX]({{< relref "commands/json.arrindex/" >}}) | [JSON.ARRINSERT]({{< relref "commands/json.arrinsert/" >}})