Skip to content

Commit 3ef226a

Browse files
Add documentation for json_get_object function
Co-authored-by: MichaelScofield <[email protected]>
1 parent ec1ee96 commit 3ef226a

File tree

2 files changed

+18
-0
lines changed
  • docs/reference/sql/functions
  • i18n/zh/docusaurus-plugin-content-docs/current/reference/sql/functions

2 files changed

+18
-0
lines changed

docs/reference/sql/functions/json.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Extracts values with specific types from JSON values through specific paths.
3636
* `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.
3737
* `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.
3838
* `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.
39+
* `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.
3940

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

@@ -63,6 +64,14 @@ SELECT json_get_int(parse_json('{"a": {"c": 3}, "b": 2}'), 'a.c');
6364
+-----------------------------------------------------------------------+
6465
| 3 |
6566
+-----------------------------------------------------------------------+
67+
68+
SELECT json_to_string(json_get_object(parse_json('{"a": {"b": {"c": {"d": 42}}}}'), 'a.b.c'));
69+
70+
+---------------------------------------------------------------------------------------------------+
71+
| json_to_string(json_get_object(parse_json(Utf8("{"a": {"b": {"c": {"d": 42}}}}")),Utf8("a.b.c"))) |
72+
+---------------------------------------------------------------------------------------------------+
73+
| {"d":42} |
74+
+---------------------------------------------------------------------------------------------------+
6675
```
6776

6877
## Validation

i18n/zh/docusaurus-plugin-content-docs/current/reference/sql/functions/json.md

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

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

@@ -63,6 +64,14 @@ SELECT json_get_int(parse_json('{"a": {"c": 3}, "b": 2}'), 'a.c');
6364
+-----------------------------------------------------------------------+
6465
| 3 |
6566
+-----------------------------------------------------------------------+
67+
68+
SELECT json_to_string(json_get_object(parse_json('{"a": {"b": {"c": {"d": 42}}}}'), 'a.b.c'));
69+
70+
+---------------------------------------------------------------------------------------------------+
71+
| json_to_string(json_get_object(parse_json(Utf8("{"a": {"b": {"c": {"d": 42}}}}")),Utf8("a.b.c"))) |
72+
+---------------------------------------------------------------------------------------------------+
73+
| {"d":42} |
74+
+---------------------------------------------------------------------------------------------------+
6675
```
6776

6877
## 验证

0 commit comments

Comments
 (0)