> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-mintlify-3a82795f.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> 计算存储在 JSON 中的不同路径及其类型列表

# distinctJSONPathsAndTypes

<div id="distinctJSONPathsAndTypes">
  ## distinctJSONPathsAndTypes
</div>

引入版本：v24.9.0

计算存储在 [JSON](/zh/reference/data-types/newjson) 列中的不同路径及其类型列表。

<Note>
  如果 JSON 声明中包含已指定类型的路径，那么即使输入数据中没有这些路径的值，这些路径也始终会包含在 `distinctJSONPaths/distinctJSONPathsAndTypes` 函数的结果中。
</Note>

**语法**

```sql theme={null}
distinctJSONPathsAndTypes(json)
```

**参数**

* `json` — JSON 列。[`JSON`](/zh/reference/data-types/newjson)

**返回值**

返回按路径排序的路径到类型的映射。[`Map(String, Array(String))`](/zh/reference/data-types/map)

**示例**

**混合类型的基本用法**

```sql title=Query theme={null}
DROP TABLE IF EXISTS test_json;
CREATE TABLE test_json(json JSON) ENGINE = Memory;
INSERT INTO test_json VALUES ('{"a" : 42, "b" : "Hello"}'), ('{"b" : [1, 2, 3], "c" : {"d" : {"e" : "2020-01-01"}}}'), ('{"a" : 43, "c" : {"d" : {"f" : [{"g" : 42}]}}}');

SELECT distinctJSONPathsAndTypes(json) FROM test_json;
```

```response title=Response theme={null}
┌─distinctJSONPathsAndTypes(json)───────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ {'a':['Int64'],'b':['Array(Nullable(Int64))','String'],'c.d.e':['Date'],'c.d.f':['Array(JSON(max_dynamic_types=16, max_dynamic_paths=256))']} │
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
```

**使用已声明的 JSON 路径**

```sql title=Query theme={null}
DROP TABLE IF EXISTS test_json;
CREATE TABLE test_json(json JSON(a UInt32)) ENGINE = Memory;
INSERT INTO test_json VALUES ('{"b" : "Hello"}'), ('{"b" : "World", "c" : [1, 2, 3]}');

SELECT distinctJSONPathsAndTypes(json) FROM test_json;
```

```response title=Response theme={null}
┌─distinctJSONPathsAndTypes(json)────────────────────────────────┐
│ {'a':['UInt32'],'b':['String'],'c':['Array(Nullable(Int64))']} │
└────────────────────────────────────────────────────────────────┘
```
