What's new in Valkey 9.0? Discover new features and improvements. Read the announcement.

JSON.DEL

Delete the JSON values at the specified path in a document key.

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

Delete the JSON values at the path in a document key. If the path is the root path, it is equivalent to deleting the key from Valkey.

Examples

Enhanced path syntax:

127.0.0.1:6379> JSON.SET k1 . '{"a":{}, "b":{"a":1}, "c":{"a":1, "b":2}, "d":{"a":1, "b":2, "c":3}, "e": [1,2,3,4,5]}'
OK
127.0.0.1:6379> JSON.DEL k1 $.d.*
(integer) 3
127.0.0.1:6379> JSON.GET k1
"{\"a\":{},\"b\":{\"a\":1},\"c\":{\"a\":1,\"b\":2},\"d\":{},\"e\":[1,2,3,4,5]}"
127.0.0.1:6379> JSON.DEL k1 $.e[*]
(integer) 5
127.0.0.1:6379> JSON.GET k1
"{\"a\":{},\"b\":{\"a\":1},\"c\":{\"a\":1,\"b\":2},\"d\":{},\"e\":[]}"

Restricted path syntax:

127.0.0.1:6379> JSON.SET k1 . '{"a":{}, "b":{"a":1}, "c":{"a":1, "b":2}, "d":{"a":1, "b":2, "c":3}, "e": [1,2,3,4,5]}'
OK
127.0.0.1:6379> JSON.DEL k1 .d.*
(integer) 3
127.0.0.1:6379> JSON.GET k1
"{\"a\":{},\"b\":{\"a\":1},\"c\":{\"a\":1,\"b\":2},\"d\":{},\"e\":[1,2,3,4,5]}"
127.0.0.1:6379> JSON.DEL k1 .e[*]
(integer) 5
127.0.0.1:6379> JSON.GET k1
"{\"a\":{},\"b\":{\"a\":1},\"c\":{\"a\":1,\"b\":2},\"d\":{},\"e\":[]}"

Replies

RESP2

  • Integer reply:
    • The number of elements deleted.
    • Returns 0 if the Valkey key does not exist.
    • Returns 0 if the JSON path is invalid or does not exist.

RESP3

  • Integer reply:
    • The number of elements deleted.
    • Returns 0 if the Valkey key does not exist.
    • Returns 0 if the JSON path is invalid or does not exist.