diff --git a/docs/reference/sql/functions/overview.md b/docs/reference/sql/functions/overview.md index a06dcfa18..325743480 100644 --- a/docs/reference/sql/functions/overview.md +++ b/docs/reference/sql/functions/overview.md @@ -271,7 +271,23 @@ SELECT json_to_string(parse_json('{"a": 1, "b": 2}')); * `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. -`path` is a string that select and extract elements from a json value. Checkout [SQL/JSONPath](https://github.com/datafuselabs/jsonb?tab=readme-ov-file#sqljsonpath) for supported `path` syntax. +`path` is a string that select and extract elements from a json value. The following operators in the path are supported: + +| Operator | Description | Examples | +|--------------------------|--------------------------------------------------------------|--------------------| +| `$` | The root element | `$` | +| `@` | The current element in the filter expression | `$.event?(@ == 1)` | +| `.*` | Selecting all elements in an Object | `$.*` | +| `.` | Selecting element that match the name in an Object | `$.event` | +| `:` | Alias of `.` | `$:event` | +| `[""]` | Alias of `.` | `$["event"]` | +| `[*]` | Selecting all elements in an Array | `$[*]` | +| `[, ..]` | Selecting 0-based `n-th` elements in an Array | `$[1, 2]` | +| `[last - , ..]` | Selecting `n-th` element before the last element in an Array | `$[0, last - 1]` | +| `[ to , ..]` | Selecting all elements of a range in an Array | `$[1 to last - 2]` | +| `?()` | Selecting all elements that matched the filter expression | `$?(@.price < 10)` | + +If the path is invalid, the function will return a NULL value. ```sql SELECT json_get_int(parse_json('{"a": {"c": 3}, "b": 2}'), 'a.c'); diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/reference/sql/functions/overview.md b/i18n/zh/docusaurus-plugin-content-docs/current/reference/sql/functions/overview.md index 2c7984589..f9aae44c7 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/reference/sql/functions/overview.md +++ b/i18n/zh/docusaurus-plugin-content-docs/current/reference/sql/functions/overview.md @@ -264,7 +264,23 @@ SELECT json_to_string(parse_json('{"a": 1, "b": 2}')); * `json_get_float(json, path)` 按照路径 `path` 从 JSON 中获取浮点数值。布尔值、整数值将被转换为浮点数。 * `json_get_string(json, path)` 按照路径 `path` 从 JSON 中获取字符串。所有类型的 JSON 值都将被转换为字符串,包括数组、对象和 null。 -`path` 是一个用于从 JSON 值中选择和提取元素的字符串。查看 [SQL/JSONPath](https://github.com/datafuselabs/jsonb?tab=readme-ov-file#sqljsonpath) 以了解支持的 `path` 语法。 +`path` 是一个用于从 JSON 值中选择和提取元素的字符串。`path` 中支持的操作符有: + +| 操作符 | 描述 | 示例 | +|--------------------------|--------------------------------------------------------------|--------------------| +| `$` | 根元素 | `$` | +| `@` | 过滤表达式中的当前元素 | `$.event?(@ == 1)` | +| `.*` | 选择对象中的所有元素 | `$.*` | +| `.` | 选择对象中匹配名称的元素 | `$.event` | +| `:` | `.` 的别名 | `$:event` | +| `[""]` | `.` 的别名 | `$["event"]` | +| `[*]` | 选择数组中的所有元素 | `$[*]` | +| `[, ..]` | 选择数组中基于0的第 `n` 个元素 | `$[1, 2]` | +| `[last - , ..]` | 选择数组中最后一个元素之前的第 `n` 个元素 | `$[0, last - 1]` | +| `[ to , ..]` | 选择数组中某个范围内的所有元素 | `$[1 to last - 2]` | +| `?()` | 选择所有匹配过滤表达式的元素 | `$?(@.price < 10)` | + +如果 `path` 是无效的,函数将返回 `NULL`。 ```sql SELECT json_get_int(parse_json('{"a": {"c": 3}, "b": 2}'), 'a.c');