Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ JSON_EXTRACT (<json_object>, <path>[, <path2>, ...])
* `*` represents a wildcard, where `$.*` represents all members of the root object, and `$[*]` represents all elements of the array.
* `**` is used in combination with '$', '$**' represents all paths (including multi-level subpaths).
- If `<path>` contains wildcards (`*`), the matching results will be returned in array form.
- `<path>` does not auto-broadcast over arrays. If `<json_object>` is a JSON array and `<path>` is `$.k`, the result is NULL — `$.k` only traverses object members. To target an element by index, use `$[i].k`; to extract a field from every element of an array, use the wildcard syntax `$[*].k`, which is supported from Doris 4.0 onward.

## Examples
1. General parameters
Expand Down Expand Up @@ -185,3 +186,27 @@ JSON_EXTRACT (<json_object>, <path>[, <path2>, ...])
| null | 0 |
+------+------+
```

11. Extracting a field from each element of a JSON array (Doris 4.0+)
```sql
select json_extract('[{"k":1},{"k":2},{"k":3}]', '$.k');
```
```
+--------------------------------------------------+
| json_extract('[{"k":1},{"k":2},{"k":3}]', '$.k') |
+--------------------------------------------------+
| NULL |
+--------------------------------------------------+
```
> `$.k` does not traverse arrays; it only descends into object members.
```sql
select json_extract('[{"k":1},{"k":2},{"k":3}]', '$[*].k');
```
```
+-----------------------------------------------------+
| json_extract('[{"k":1},{"k":2},{"k":3}]', '$[*].k') |
+-----------------------------------------------------+
| [1,2,3] |
+-----------------------------------------------------+
```
> Use `$[*].k` to extract the field from every element of the array.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ JSON_EXTRACT (<json_object>, <path>[, <path2>, ...])
* `**` 代表通配符,通常和 '$' 一起使用: '$**' 代表所有的路径(以及多层的子路径,见下面的示例 9)。

- 如果 `<path>` 存在通配符(`*`),匹配的结果会以数组形式返回。
- `<path>` 不会在数组上自动广播。如果 `<json_object>` 是 JSON 数组,`<path>` 为 `$.k`,结果为 NULL —— `$.k` 只会遍历 object 的成员。要按下标访问元素,使用 `$[i].k`;要从数组的每个元素中提取字段,使用通配符语法 `$[*].k`,该语法自 Doris 4.0 起支持。

## 示例
1. 一般参数
Expand Down Expand Up @@ -185,3 +186,27 @@ JSON_EXTRACT (<json_object>, <path>[, <path2>, ...])
| null | 0 |
+------+------+
```

11. 从 JSON 数组的每个元素中提取字段(Doris 4.0+)
```sql
select json_extract('[{"k":1},{"k":2},{"k":3}]', '$.k');
```
```
+--------------------------------------------------+
| json_extract('[{"k":1},{"k":2},{"k":3}]', '$.k') |
+--------------------------------------------------+
| NULL |
+--------------------------------------------------+
```
> `$.k` 不会遍历数组,只会下钻到对象的成员。
```sql
select json_extract('[{"k":1},{"k":2},{"k":3}]', '$[*].k');
```
```
+-----------------------------------------------------+
| json_extract('[{"k":1},{"k":2},{"k":3}]', '$[*].k') |
+-----------------------------------------------------+
| [1,2,3] |
+-----------------------------------------------------+
```
> 使用 `$[*].k` 从数组的每个元素提取字段。
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
## 别名
* JSONB_EXTRACT 同 `JSON_EXTRACT`
* JSONB_EXTRACT_ISNULL 同 `JSON_EXTRACT_ISNULL`
* JSONB_EXTRACT_BOOL 同 `JSON_EXTRACT_BOOL`

Check notice on line 23 in i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/json-functions/json-extract.md

View workflow job for this annotation

GitHub Actions / Build Check

sql-function-syntax-sql-code-block

Syntax section must contain only one fenced sql code block. Owner%3A @zclllyybb
* JSONB_EXTRACT_INT 同 `JSON_EXTRACT_INT`
* JSONB_EXTRACT_BIGINT 同 `JSON_EXTRACT_BIGINT`
* JSONB_EXTRACT_LARGEINT 同 `JSON_EXTRACT_LARGEINT`
Expand Down Expand Up @@ -67,6 +67,8 @@
* '[i]' 代表 json array 中下标为 i 的元素
- 获取 json_array 的最后一个元素可以用'$[last]',倒数第二个元素可以用'$[last-1]',以此类推。

`<path>` 不会在数组上自动广播:如果 JSON 值是数组、`<path>` 为 `$.k`,结果为 NULL,因为 `$.k` 只会遍历 object 的成员。要按下标访问元素,使用 `$[i].k`。通过 `$[*].k` 在数组上广播取值是 Doris 4.0 引入的能力;在 2.1 和 3.x 上请改用 `LATERAL VIEW EXPLODE` 等方式逐元素展开后再 `json_extract`。

## 返回值
根据要提取的字段类型不同,返回目标 JSON 中 指定 JSON_PATH 的数据类型。特殊情况处理如下:
* 如果 json_path 指定的字段在 JSON 中不存在,返回 NULL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ JSON_EXTRACT_STRING (<json_str>, <path>)
* '[i]' 代表 json array 中下标为 i 的元素
- 获取 json_array 的最后一个元素可以用'$[last]',倒数第二个元素可以用'$[last-1]',以此类推。

`<path>` 不会在数组上自动广播:如果 JSON 值是数组、`<path>` 为 `$.k`,结果为 NULL,因为 `$.k` 只会遍历 object 的成员。要按下标访问元素,使用 `$[i].k`。通过 `$[*].k` 在数组上广播取值是 Doris 4.0 引入的能力;在 2.1 和 3.x 上请改用 `LATERAL VIEW EXPLODE` 等方式逐元素展开后再 `json_extract`。

## 返回值
根据要提取的字段类型不同,返回目标 JSON 中 指定 JSON_PATH 的数据类型。特殊情况处理如下:
* 如果 json_path 指定的字段在 JSON 中不存在,返回 NULL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
* `**` 代表通配符,通常和 '$' 一起使用: '$**' 代表所有的路径(以及多层的子路径,见下面的示例 9)。

- 如果 `<path>` 存在通配符(`*`),匹配的结果会以数组形式返回。
- `<path>` 不会在数组上自动广播。如果 `<json_object>` 是 JSON 数组,`<path>` 为 `$.k`,结果为 NULL —— `$.k` 只会遍历 object 的成员。要按下标访问元素,使用 `$[i].k`;要从数组的每个元素中提取字段,使用通配符语法 `$[*].k`,该语法自 Doris 4.0 起支持。

Check warning on line 42 in i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/json-functions/json-extract.md

View workflow job for this annotation

GitHub Actions / Build Check

markdown-code-fence-language

Code fence should declare a language. Owner%3A @zclllyybb

## 示例
1. 一般参数
Expand All @@ -50,7 +51,7 @@
| JSON_EXTRACT('{"k1":"v31","k2":300}', '$.k1') |
+-----------------------------------------------+
| "v31" |
+-----------------------------------------------+

Check warning on line 54 in i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/json-functions/json-extract.md

View workflow job for this annotation

GitHub Actions / Build Check

markdown-code-fence-language

Code fence should declare a language. Owner%3A @zclllyybb
```
> 注意:返回的结果是`"v31"` 不是 `v31`。
2. NULL 参数
Expand All @@ -61,7 +62,7 @@
+----------------------------+
| JSON_EXTRACT(null, '$.k1') |
+----------------------------+
| NULL |

Check warning on line 65 in i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/json-functions/json-extract.md

View workflow job for this annotation

GitHub Actions / Build Check

markdown-code-fence-language

Code fence should declare a language. Owner%3A @zclllyybb
+----------------------------+
```
3. `<path>` 为 NULL
Expand All @@ -72,7 +73,7 @@
+---------------------------------------------+
| JSON_EXTRACT('{"k1":"v31","k2":300}', NULL) |
+---------------------------------------------+
| NULL |

Check warning on line 76 in i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/json-functions/json-extract.md

View workflow job for this annotation

GitHub Actions / Build Check

markdown-code-fence-language

Code fence should declare a language. Owner%3A @zclllyybb
+---------------------------------------------+
```
4. 多级路径
Expand All @@ -83,7 +84,7 @@
+------------------------------------------------------------------------+
| JSON_EXTRACT('{"k1":"v31","k2":{"sub_key": 1234.56}}', '$.k2.sub_key') |
+------------------------------------------------------------------------+
| 1234.56 |

Check warning on line 87 in i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/json-functions/json-extract.md

View workflow job for this annotation

GitHub Actions / Build Check

markdown-code-fence-language

Code fence should declare a language. Owner%3A @zclllyybb
+------------------------------------------------------------------------+
```
5. 数组路径
Expand All @@ -94,7 +95,7 @@
+----------------------------------------------------------------------+
| JSON_EXTRACT(json_array("abc", 123, cast(now() as string)), '$.[2]') |
+----------------------------------------------------------------------+
| "2025-07-16 18:35:25" |

Check warning on line 98 in i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/json-functions/json-extract.md

View workflow job for this annotation

GitHub Actions / Build Check

markdown-code-fence-language

Code fence should declare a language. Owner%3A @zclllyybb
+----------------------------------------------------------------------+
```
6. 不存在的 path
Expand All @@ -105,7 +106,7 @@
+-----------------------------------------------+
| JSON_EXTRACT('{"k1":"v31","k2":300}', '$.k3') |
+-----------------------------------------------+
| NULL |

Check warning on line 109 in i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/json-functions/json-extract.md

View workflow job for this annotation

GitHub Actions / Build Check

markdown-code-fence-language

Code fence should declare a language. Owner%3A @zclllyybb
+-----------------------------------------------+
```
7. 多个路径参数
Expand All @@ -116,7 +117,7 @@
+--------------------------------------------------------------------------------+
| JSON_EXTRACT('{"id": 123, "name": "doris"}', '$.name', '$.id', '$.not_exists') |
+--------------------------------------------------------------------------------+
| ["doris",123] |

Check warning on line 120 in i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/json-functions/json-extract.md

View workflow job for this annotation

GitHub Actions / Build Check

markdown-code-fence-language

Code fence should declare a language. Owner%3A @zclllyybb
+--------------------------------------------------------------------------------+
```
> 即使只有一个匹配也会以数组形式返回
Expand All @@ -127,7 +128,7 @@
+---------------------------------------------------------------------------------+
| JSON_EXTRACT('{"id": 123, "name": "doris"}', '$.name', '$.id2', '$.not_exists') |
+---------------------------------------------------------------------------------+
| ["doris"] |

Check warning on line 131 in i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/json-functions/json-extract.md

View workflow job for this annotation

GitHub Actions / Build Check

markdown-code-fence-language

Code fence should declare a language. Owner%3A @zclllyybb
+---------------------------------------------------------------------------------+
```
```sql
Expand All @@ -139,7 +140,7 @@
| JSON_EXTRACT('{"id": 123, "name": "doris"}', '$.k1', '$.k2', '$.not_exists') |
+------------------------------------------------------------------------------+
| NULL |
+------------------------------------------------------------------------------+

Check warning on line 143 in i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/json-functions/json-extract.md

View workflow job for this annotation

GitHub Actions / Build Check

markdown-code-fence-language

Code fence should declare a language. Owner%3A @zclllyybb
```

8. 通配符路径
Expand Down Expand Up @@ -185,3 +186,27 @@
| null | 0 |
+------+------+
```

11. 从 JSON 数组的每个元素中提取字段(Doris 4.0+)
```sql
select json_extract('[{"k":1},{"k":2},{"k":3}]', '$.k');
```
```
+--------------------------------------------------+
| json_extract('[{"k":1},{"k":2},{"k":3}]', '$.k') |
+--------------------------------------------------+
| NULL |
+--------------------------------------------------+
```
> `$.k` 不会遍历数组,只会下钻到对象的成员。
```sql
select json_extract('[{"k":1},{"k":2},{"k":3}]', '$[*].k');
```
```
+-----------------------------------------------------+
| json_extract('[{"k":1},{"k":2},{"k":3}]', '$[*].k') |
+-----------------------------------------------------+
| [1,2,3] |
+-----------------------------------------------------+
```
> 使用 `$[*].k` 从数组的每个元素提取字段。
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
## Alias
* JSONB_EXTRACT is the same as JSON_EXTRACT.
* JSONB_EXTRACT_ISNULL is the same as JSON_EXTRACT_ISNULL.
* JSONB_EXTRACT_BOOL is the same as JSON_EXTRACT_BOOL.

Check notice on line 24 in versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/json-functions/json-extract.md

View workflow job for this annotation

GitHub Actions / Build Check

sql-function-syntax-sql-code-block

Syntax section must contain only one fenced sql code block. Owner%3A @zclllyybb
* JSONB_EXTRACT_INT is the same as JSON_EXTRACT_INT.
* JSONB_EXTRACT_BIGINT is the same as JSON_EXTRACT_BIGINT.
* JSONB_EXTRACT_LARGEINT is the same as JSON_EXTRACT_LARGEINT.
Expand Down Expand Up @@ -67,6 +67,8 @@
- '[i]' for element of json array at index i
- Use '$[last]' to get the last element of json_array, and '$[last-1]' to get the penultimate element, and so on.

`<path>` does not auto-broadcast over arrays: if the JSON value is an array and `<path>` is `$.k`, the result is NULL because `$.k` only traverses object members. To target an element by index use `$[i].k`. Array-wildcard broadcasting via `$[*].k` was introduced in Doris 4.0; on 2.1 and 3.x, extract per-element values via `LATERAL VIEW EXPLODE` patterns instead.

## Return Values
According to the type of the field to be extracted, return the data type of the specified JSON_PATH in the target JSON. Special case handling is as follows:
* If the field specified by json_path does not exist in the JSON, return NULL.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---

Check notice on line 1 in versioned_docs/version-3.x/sql-manual/sql-functions/scalar-functions/json-functions/json-extract.md

View workflow job for this annotation

GitHub Actions / Build Check

i18n-sync-locale-candidate

Japanese docs are report-only. Generate a candidate translation from the changed files and merge it only after human review. Owner%3A @zclllyybb
{
"title": "JSON_EXTRACT",
"language": "en",
Expand Down Expand Up @@ -76,6 +76,8 @@
- '[i]' for element of json array at index i
- Use '$[last]' to get the last element of json_array, and '$[last-1]' to get the penultimate element, and so on.

`<path>` does not auto-broadcast over arrays: if the JSON value is an array and `<path>` is `$.k`, the result is NULL because `$.k` only traverses object members. To target an element by index use `$[i].k`. Array-wildcard broadcasting via `$[*].k` was introduced in Doris 4.0; on 2.1 and 3.x, extract per-element values via `LATERAL VIEW EXPLODE` patterns instead.

## Return Values
According to the type of the field to be extracted, return the data type of the specified JSON_PATH in the target JSON. Special case handling is as follows:
* If the field specified by json_path does not exist in the JSON, return NULL.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---

Check notice on line 1 in versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/json-functions/json-extract.md

View workflow job for this annotation

GitHub Actions / Build Check

i18n-sync-locale-candidate

Japanese docs are report-only. Generate a candidate translation from the changed files and merge it only after human review. Owner%3A @zclllyybb
{
"title": "JSON_EXTRACT",
"language": "en",
Expand Down Expand Up @@ -38,6 +38,7 @@
* `*` represents a wildcard, where `$.*` represents all members of the root object, and `$[*]` represents all elements of the array.
* `**` is used in combination with '$', '$**' represents all paths (including multi-level subpaths).
- If `<path>` contains wildcards (`*`), the matching results will be returned in array form.
- `<path>` does not auto-broadcast over arrays. If `<json_object>` is a JSON array and `<path>` is `$.k`, the result is NULL — `$.k` only traverses object members. To target an element by index, use `$[i].k`; to extract a field from every element of an array, use the wildcard syntax `$[*].k`, which is supported from Doris 4.0 onward.

## Examples
1. General parameters
Expand Down Expand Up @@ -185,3 +186,27 @@
| null | 0 |
+------+------+
```

11. Extracting a field from each element of a JSON array (Doris 4.0+)
```sql
select json_extract('[{"k":1},{"k":2},{"k":3}]', '$.k');
```
```
+--------------------------------------------------+
| json_extract('[{"k":1},{"k":2},{"k":3}]', '$.k') |
+--------------------------------------------------+
| NULL |
+--------------------------------------------------+
```
> `$.k` does not traverse arrays; it only descends into object members.
```sql
select json_extract('[{"k":1},{"k":2},{"k":3}]', '$[*].k');
```
```
+-----------------------------------------------------+
| json_extract('[{"k":1},{"k":2},{"k":3}]', '$[*].k') |
+-----------------------------------------------------+
| [1,2,3] |
+-----------------------------------------------------+
```
> Use `$[*].k` to extract the field from every element of the array.
Loading