Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/reference/sql/functions/json.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Extracts values with specific types from JSON values through specific paths.
* `json_get_int(json, path)` to extract an integer value from a JSON value by the path, while boolean values will be converted to integers.
* `json_get_float(json, path)` to extract a float value from a JSON value by the path, while integer and boolean values will be converted to floats.
* `json_get_string(json, path)` to extract a string value from a JSON value by the path. All valid JSON values will be converted to strings, including null values, objects and arrays.
* `json_get_object(json, path)` to extract an object value from a JSON value by the path. Returns NULL if the path does not point to an object.

`path` is a string that select and extract elements from a json value. The following operators in the path are supported:

Expand Down Expand Up @@ -63,6 +64,14 @@ SELECT json_get_int(parse_json('{"a": {"c": 3}, "b": 2}'), 'a.c');
+-----------------------------------------------------------------------+
| 3 |
+-----------------------------------------------------------------------+

SELECT json_to_string(json_get_object(parse_json('{"a": {"b": {"c": {"d": 42}}}}'), 'a.b.c'));

+---------------------------------------------------------------------------------------------------+
| json_to_string(json_get_object(parse_json(Utf8("{"a": {"b": {"c": {"d": 42}}}}")),Utf8("a.b.c"))) |
+---------------------------------------------------------------------------------------------------+
| {"d":42} |
+---------------------------------------------------------------------------------------------------+
```

## Validation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ SELECT json_to_string(parse_json('{"a": 1, "b": 2}'));
* `json_get_int(json, path)` 按照路径 `path` 从 JSON 中获取整数值。布尔值将被转换为整数。
* `json_get_float(json, path)` 按照路径 `path` 从 JSON 中获取浮点数值。布尔值、整数值将被转换为浮点数。
* `json_get_string(json, path)` 按照路径 `path` 从 JSON 中获取字符串。所有类型的 JSON 值都将被转换为字符串,包括数组、对象和 null。
* `json_get_object(json, path)` 按照路径 `path` 从 JSON 中获取对象值。如果路径未指向对象,则返回 NULL。

`path` 是一个用于从 JSON 值中选择和提取元素的字符串。`path` 中支持的操作符有:

Expand Down Expand Up @@ -63,6 +64,14 @@ SELECT json_get_int(parse_json('{"a": {"c": 3}, "b": 2}'), 'a.c');
+-----------------------------------------------------------------------+
| 3 |
+-----------------------------------------------------------------------+

SELECT json_to_string(json_get_object(parse_json('{"a": {"b": {"c": {"d": 42}}}}'), 'a.b.c'));

+---------------------------------------------------------------------------------------------------+
| json_to_string(json_get_object(parse_json(Utf8("{"a": {"b": {"c": {"d": 42}}}}")),Utf8("a.b.c"))) |
+---------------------------------------------------------------------------------------------------+
| {"d":42} |
+---------------------------------------------------------------------------------------------------+
```

## 验证
Expand Down