Skip to content

Commit d3d186c

Browse files
b41shChasen-Zhang
andauthored
docs: add json_strip_nulls function (#3107)
* docs: add json_strip_nulls function * fix * fix * fix * fix * fix --------- Co-authored-by: Q <787025321@qq.com>
1 parent 1ef0cf3 commit d3d186c

8 files changed

Lines changed: 123 additions & 23 deletions

File tree

docs/cn/sql-reference/20-sql-functions/10-semi-structured-functions/0-json/index.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,15 @@ title: JSON 函数
4444
| [JSON_EXTRACT_PATH_TEXT](json/json-extract-path-text) | 使用路径从 JSON 提取文本值 | `JSON_EXTRACT_PATH_TEXT('{"name":"John"}', 'name')``'John'` |
4545
| [JSON_EACH](json/json-each) | 将 JSON 对象展开为键值对 | `JSON_EACH('{"a":1,"b":2}')``[("a",1),("b",2)]` |
4646
| [JSON_ARRAY_ELEMENTS](json/json-array-elements) | 将 JSON 数组展开为单个元素 | `JSON_ARRAY_ELEMENTS('[1,2,3]')``1, 2, 3` |
47+
| [JQ](json/jq) | 使用 jq 风格查询处理 JSON | `JQ('{"name":"John"}', '.name')``"John"` |
4748

4849
## JSON 格式化与处理
4950

5051
| 函数 | 描述 | 示例 |
5152
|----------|-------------|---------|
5253
| [JSON_PRETTY](json/json-pretty) | 以适当缩进格式化 JSON | `JSON_PRETTY('{"a":1}')` → 格式化后的 JSON 字符串 |
53-
| [STRIP_NULL_VALUE](json/strip-null-value) | JSON 中移除 null 值 | `STRIP_NULL_VALUE('{"a":1,"b":null}')``{"a":1}` |
54-
| [JQ](json/jq) | 使用 jq 风格查询处理 JSON | `JQ('{"name":"John"}', '.name')``"John"` |
54+
| [STRIP_NULL_VALUE](json/strip-null-value) | JSON null 值转换为 SQL 的 NULL | `STRIP_NULL_VALUE(parse_json('null'))``NULL` |
55+
| [JSON_STRIP_NULLS](json/json-strip-nulls) | 从 JSON 对象中移除 null 值 | `JSON_STRIP_NULLS(PARSE_JSON('{"a":1,"b":null}'))``{"a":1}` |
5556

5657
## JSON 包含与键检测
5758

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: JSON_STRIP_NULLS
3+
---
4+
import FunctionDescription from '@site/src/components/FunctionDescription';
5+
6+
<FunctionDescription description="引入或更新于:v1.2.762"/>
7+
8+
从 JSON 对象中移除所有值为 null 的属性。
9+
10+
## 语法
11+
12+
```sql
13+
JSON_STRIP_NULLS(<variant_expr>)
14+
```
15+
16+
## 参数
17+
18+
VARIANT 类型的表达式。
19+
20+
## 返回类型
21+
22+
VARIANT 类型。
23+
24+
## 示例
25+
26+
```sql
27+
SELECT JSON_STRIP_NULLS(PARSE_JSON('{"name": "Alice", "age": 30, "city": null}')) AS value;
28+
29+
╭───────────────────────────╮
30+
│ value │
31+
├───────────────────────────┤
32+
│ {"age":30,"name":"Alice"} │
33+
╰───────────────────────────╯
34+
```
Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,43 @@
11
---
22
title: STRIP_NULL_VALUE
3-
title_includes: JSON_STRIP_NULLS
43
---
54
import FunctionDescription from '@site/src/components/FunctionDescription';
65

76
<FunctionDescription description="引入或更新于:v1.2.762"/>
87

9-
JSON 对象中移除所有值为 null 的属性
8+
JSON null 值转换为 SQL 的 NULL 值。所有其它 Variant 值均保持不变
109

1110
## 语法
1211

1312
```sql
14-
STRIP_NULL_VALUE(<json_string>)
13+
STRIP_NULL_VALUE(<variant_expr>)
1514
```
1615

16+
## 参数
17+
18+
VARIANT 类型的表达式。
19+
1720
## 返回类型
1821

19-
返回与输入 JSON 值相同类型的值。
22+
- 如果表达式为 JSON 的 null 值,则该函数返回 SQL NULL。
23+
- 如果表达式不是 JSON 的 null 值,则该函数返回输入值。
2024

2125
## 示例
2226

2327
```sql
24-
SELECT STRIP_NULL_VALUE(PARSE_JSON('{"name": "Alice", "age": 30, "city": null}'));
28+
SELECT STRIP_NULL_VALUE(PARSE_JSON('null')) AS value;
29+
30+
╭───────╮
31+
│ value │
32+
├───────┤
33+
NULL
34+
╰───────╯
35+
36+
SELECT STRIP_NULL_VALUE(PARSE_JSON('{"name": "Alice", "age": 30, "city": null}')) AS value;
2537

26-
strip_null_value(parse_json('{"name": "alice", "age": 30, "city": null}'))|
27-
--------------------------------------------------------------------------+
28-
{"age":30,"name":"Alice"} |
38+
╭───────────────────────────────────────╮
39+
│ value │
40+
├───────────────────────────────────────┤
41+
│ {"age":30,"city":null,"name":"Alice"} │
42+
╰───────────────────────────────────────╯
2943
```

docs/cn/sql-reference/20-sql-functions/10-semi-structured-functions/index.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ Databend 中的结构化与半结构化函数能够高效处理数组(Array)
3636
|----------|-------------|--------|
3737
| [JSON_TO_STRING](semi-structured-functions/json/json-to-string) | 将 JSON 值转换为字符串 | `JSON_TO_STRING(PARSE_JSON('{"a":1}'))` |
3838
| [JSON_PRETTY](semi-structured-functions/json/json-pretty) | 使用适当缩进格式化 JSON | `JSON_PRETTY(PARSE_JSON('{"a":1}'))` |
39-
| [STRIP_NULL_VALUE](semi-structured-functions/json/strip-null-value) | 从 JSON 中移除 null 值 | `STRIP_NULL_VALUE(PARSE_JSON('{"a":1,"b":null}'))` |
39+
| [STRIP_NULL_VALUE](semi-structured-functions/json/strip-null-value) | 将 JSON 的 null 值转换为 SQL 的 NULL 值 | `STRIP_NULL_VALUE(parse_json('null'))``NULL` |
40+
| [JSON_STRIP_NULLS](semi-structured-functions/json/json-strip-nulls) | 从 JSON 对象中移除 null 值 | `JSON_STRIP_NULLS(PARSE_JSON('{"a":1,"b":null}'))``{"a":1}` |
4041

4142
### 数组/对象展开
4243
| 函数 | 描述 | 示例 |
@@ -130,4 +131,4 @@ Databend 中的结构化与半结构化函数能够高效处理数组(Array)
130131
| [IS_INTEGER](semi-structured-functions/type-predicate/is-integer) | 检查 JSON 值是否为整数 | `IS_INTEGER(PARSE_JSON('42'))` |
131132
| [IS_FLOAT](semi-structured-functions/type-predicate/is-float) | 检查 JSON 值是否为浮点数 | `IS_FLOAT(PARSE_JSON('3.14'))` |
132133
| [IS_BOOLEAN](semi-structured-functions/type-predicate/is-boolean) | 检查 JSON 值是否为 BOOLEAN | `IS_BOOLEAN(PARSE_JSON('true'))` |
133-
| [IS_NULL_VALUE](semi-structured-functions/type-predicate/is-null-value) | 检查 JSON 值是否为 null | `IS_NULL_VALUE(PARSE_JSON('null'))` |
134+
| [IS_NULL_VALUE](semi-structured-functions/type-predicate/is-null-value) | 检查 JSON 值是否为 null | `IS_NULL_VALUE(PARSE_JSON('null'))` |

docs/en/sql-reference/20-sql-functions/10-semi-structured-functions/0-json/index.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,15 @@ This section provides reference information for JSON functions in Databend. JSON
4444
| [JSON_EXTRACT_PATH_TEXT](json/json-extract-path-text) | Extracts text value from JSON using path | `JSON_EXTRACT_PATH_TEXT('{"name":"John"}', 'name')``'John'` |
4545
| [JSON_EACH](json/json-each) | Expands JSON object into key-value pairs | `JSON_EACH('{"a":1,"b":2}')``[("a",1),("b",2)]` |
4646
| [JSON_ARRAY_ELEMENTS](json/json-array-elements) | Expands JSON array into individual elements | `JSON_ARRAY_ELEMENTS('[1,2,3]')``1, 2, 3` |
47+
| [JQ](json/jq) | Processes JSON using jq-style queries | `JQ('{"name":"John"}', '.name')``"John"` |
4748

4849
## JSON Formatting & Processing
4950

5051
| Function | Description | Example |
5152
|----------|-------------|---------|
5253
| [JSON_PRETTY](json/json-pretty) | Formats JSON with proper indentation | `JSON_PRETTY('{"a":1}')` → Formatted JSON string |
53-
| [STRIP_NULL_VALUE](json/strip-null-value) | Removes null values from JSON | `STRIP_NULL_VALUE('{"a":1,"b":null}')``{"a":1}` |
54-
| [JQ](json/jq) | Processes JSON using jq-style queries | `JQ('{"name":"John"}', '.name')``"John"` |
54+
| [STRIP_NULL_VALUE](json/strip-null-value) | Converts a JSON null value to a SQL NULL value | `STRIP_NULL_VALUE(parse_json('null'))``NULL` |
55+
| [JSON_STRIP_NULLS](json/json-strip-nulls) | Removes null values from JSON Object | `JSON_STRIP_NULLS(PARSE_JSON('{"a":1,"b":null}'))``{"a":1}` |
5556

5657
## JSON Containment & Existence
5758

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: JSON_STRIP_NULLS
3+
---
4+
import FunctionDescription from '@site/src/components/FunctionDescription';
5+
6+
<FunctionDescription description="Introduced or updated: v1.2.762"/>
7+
8+
Removes all properties with null values from a JSON object.
9+
10+
## Syntax
11+
12+
```sql
13+
JSON_STRIP_NULLS(<variant_expr>)
14+
```
15+
16+
## Arguments
17+
18+
An expression of type VARIANT.
19+
20+
## Return Type
21+
22+
VARIANT.
23+
24+
## Examples
25+
26+
```sql
27+
SELECT JSON_STRIP_NULLS(PARSE_JSON('{"name": "Alice", "age": 30, "city": null}')) AS value;
28+
29+
╭───────────────────────────╮
30+
│ value │
31+
├───────────────────────────┤
32+
│ {"age":30,"name":"Alice"} │
33+
╰───────────────────────────╯
34+
```
Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,43 @@
11
---
22
title: STRIP_NULL_VALUE
3-
title_includes: JSON_STRIP_NULLS
43
---
54
import FunctionDescription from '@site/src/components/FunctionDescription';
65

76
<FunctionDescription description="Introduced or updated: v1.2.762"/>
87

9-
Removes all properties with null values from a JSON object.
8+
Converts a JSON null value to a SQL NULL value. All other variant values are passed unchanged.
109

1110
## Syntax
1211

1312
```sql
14-
STRIP_NULL_VALUE(<json_string>)
13+
STRIP_NULL_VALUE(<variant_expr>)
1514
```
1615

16+
## Arguments
17+
18+
An expression of type VARIANT.
19+
1720
## Return Type
1821

19-
Returns a value of the same type as the input JSON value.
22+
- If the expression is a JSON null value, the function returns a SQL NULL.
23+
- If the expression is not a JSON null value, the function returns the input value.
2024

2125
## Examples
2226

2327
```sql
24-
SELECT STRIP_NULL_VALUE(PARSE_JSON('{"name": "Alice", "age": 30, "city": null}'));
28+
SELECT STRIP_NULL_VALUE(PARSE_JSON('null')) AS value;
29+
30+
╭───────╮
31+
│ value │
32+
├───────┤
33+
NULL
34+
╰───────╯
35+
36+
SELECT STRIP_NULL_VALUE(PARSE_JSON('{"name": "Alice", "age": 30, "city": null}')) AS value;
2537

26-
strip_null_value(parse_json('{"name": "alice", "age": 30, "city": null}'))|
27-
--------------------------------------------------------------------------+
28-
{"age":30,"name":"Alice"} |
38+
╭───────────────────────────────────────╮
39+
│ value │
40+
├───────────────────────────────────────┤
41+
│ {"age":30,"city":null,"name":"Alice"} │
42+
╰───────────────────────────────────────╯
2943
```

docs/en/sql-reference/20-sql-functions/10-semi-structured-functions/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ Structured and semi-structured functions in Databend enable efficient processing
3636
|----------|-------------|--------|
3737
| [JSON_TO_STRING](semi-structured-functions/json/json-to-string) | Converts a JSON value to a string | `JSON_TO_STRING(PARSE_JSON('{"a":1}'))` |
3838
| [JSON_PRETTY](semi-structured-functions/json/json-pretty) | Formats JSON with proper indentation | `JSON_PRETTY(PARSE_JSON('{"a":1}'))` |
39-
| [STRIP_NULL_VALUE](semi-structured-functions/json/strip-null-value) | Removes null values from JSON | `STRIP_NULL_VALUE(PARSE_JSON('{"a":1,"b":null}'))` |
39+
| [STRIP_NULL_VALUE](semi-structured-functions/json/strip-null-value) | Converts a JSON null value to a SQL NULL value | `STRIP_NULL_VALUE(parse_json('null'))``NULL` |
40+
| [JSON_STRIP_NULLS](semi-structured-functions/json/json-strip-nulls) | Removes null values from JSON Object | `JSON_STRIP_NULLS(PARSE_JSON('{"a":1,"b":null}'))``{"a":1}` |
4041

4142
### Array/Object Expansion
4243
| Function | Description | Example |

0 commit comments

Comments
 (0)