JSON.DEL - Amazon ElastiCache

JSON.DEL

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

Syntax

JSON.DEL <key> [path]
  • key (required) – A Valkey or Redis OSS key of JSON document type.

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

Return

  • Number of elements deleted.

  • 0 if the Valkey or Redis OSS key does not exist.

  • 0 if the JSON path is invalid or does not exist.

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\":[]}"