diff --git a/docs/reference/sql/functions/json.md b/docs/reference/sql/functions/json.md index 4e720ce1d..c5df6fece 100644 --- a/docs/reference/sql/functions/json.md +++ b/docs/reference/sql/functions/json.md @@ -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: @@ -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 diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/reference/sql/functions/json.md b/i18n/zh/docusaurus-plugin-content-docs/current/reference/sql/functions/json.md index e9baee179..320e6d0b0 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/reference/sql/functions/json.md +++ b/i18n/zh/docusaurus-plugin-content-docs/current/reference/sql/functions/json.md @@ -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` 中支持的操作符有: @@ -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} | ++---------------------------------------------------------------------------------------------------+ ``` ## 验证