

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 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.
```