

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# JSON.DEBUG
<a name="json-debug"></a>

報告資訊。支援的子命令如下：
+ MEMORY <key> 【path】 – 以 JSON 值的位元組為單位報告記憶體用量。如果未提供，路徑預設為根。
+ DEPTH <key> 【path】 – 報告 JSON 文件的最大路徑深度。
**注意**  
此子命令僅適用於使用 Valkey 7.2 或更新版本，或 Redis OSS 引擎版本 6.2.6.R2 或更新版本。
+ FIELDS <key> 【path】 – 報告指定文件路徑中的欄位數目。如果未提供，路徑預設為根。每個非容器 JSON 值都計為一個欄位。物件和陣列遞迴計為每個內含 JSON 值的一個欄位。除根容器外，每個容器值都計為一個附加欄位。
+ HELP – 列印 命令的說明訊息。

語法

```
JSON.DEBUG <subcommand & arguments>
```

取決於子命令：

MEMORY
+ 如果路徑是增強型語法：
  + 傳回整數陣列，代表每個路徑上 JSON 值的記憶體大小 （以位元組為單位）。
  + 如果金鑰不存在， 會傳回空陣列。
+ 如果路徑是受限語法：
  + 傳回整數，記憶體大小以位元組為單位的 JSON 值。
  + 如果金鑰不存在，則傳回 null。

DEPTH
+ 傳回代表 JSON 文件最大路徑深度的整數。
+ 如果金鑰不存在，則傳回 null。

FIELDS
+ 如果路徑是增強型語法：
  + 傳回整數陣列，代表每個路徑的 JSON 值欄位數。
  + 如果金鑰不存在， 會傳回空陣列。
+ 如果路徑是受限語法：
  + 傳回整數，JSON 值的欄位數目。
  + 如果金鑰不存在，則傳回 null。

HELP – 傳回一系列說明訊息。

**範例**

增強型路徑語法：

```
127.0.0.1:6379> JSON.SET k1 . '[1, 2.3, "foo", true, null, {}, [], {"a":1, "b":2}, [1,2,3]]'
OK
127.0.0.1:6379> JSON.DEBUG MEMORY k1 $[*]
1) (integer) 16
2) (integer) 16
3) (integer) 19
4) (integer) 16
5) (integer) 16
6) (integer) 16
7) (integer) 16
8) (integer) 50
9) (integer) 64
127.0.0.1:6379> JSON.DEBUG FIELDS k1 $[*]
1) (integer) 1
2) (integer) 1
3) (integer) 1
4) (integer) 1
5) (integer) 1
6) (integer) 0
7) (integer) 0
8) (integer) 2
9) (integer) 3
```

受限路徑語法：

```
127.0.0.1:6379> JSON.SET k1 . '{"firstName":"John","lastName":"Smith","age":27,"weight":135.25,"isAlive":true,"address":{"street":"21 2nd Street","city":"New York","state":"NY","zipcode":"10021-3100"},"phoneNumbers":[{"type":"home","number":"212 555-1234"},{"type":"office","number":"646 555-4567"}],"children":[],"spouse":null}'
OK
127.0.0.1:6379> JSON.DEBUG MEMORY k1
(integer) 632
127.0.0.1:6379> JSON.DEBUG MEMORY k1 .phoneNumbers
(integer) 166

127.0.0.1:6379> JSON.DEBUG FIELDS k1
(integer) 19
127.0.0.1:6379> JSON.DEBUG FIELDS k1 .address
(integer) 4

127.0.0.1:6379> JSON.DEBUG HELP
1) JSON.DEBUG MEMORY <key> [path] - report memory size (bytes) of the JSON element. Path defaults to root if not provided.
2) JSON.DEBUG FIELDS <key> [path] - report number of fields in the JSON element. Path defaults to root if not provided.
3) JSON.DEBUG HELP - print help message.
```