yiguolei commented on code in PR #2582:
URL: https://github.com/apache/doris-website/pull/2582#discussion_r2184131775


##########
i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/json-functions/json-array.md:
##########
@@ -5,73 +5,82 @@
 }
 ---
 
-## 描述
-
-生成一个包含制定元素的 json 数组,未指定时返回空数组 
-
+# JSON_ARRAY
+## 功能
+生成一个包含指定元素的 json 数组,未传入参数时返回空数组。
 ## 语法
-
 ```sql
-JSON_ARRAY(<a>, ...)   
+JSON_ARRAY([<expression>, ...]) 
 ```
-
 ## 参数
-
-| 参数 | 描述                                                         |
-|------|------------------------------------------------------------|
-| `<a>, ...` | 要包含在 JSON 数组中的元素。可以是单个或者多个任意类型的值,包括`NULL`。如果没有指定元素,则返回一个空数组。 |
-
+### 可变参数:
+- `<expression>`: 要包含在 JSON 数组中的元素。可以是单个或者多种类型的值,包括NULL。
 ## 返回值
-
-返回一个包含指定元素的 JSON 数组。特殊情况:
-* 如果指定的元素为`NULL`,则返回`NULL`。
+[`JSON`](../../../basic-element/sql-data-types/semi-structured/JSON.md): 
返回由参数列表组成的 JSON 数组。
+
+## 使用说明
+- JSON_ARRAY 的实现是通过将不同类型的参数通过隐式调用 [`TO_JSON`](./to-json.md) 函数将其转换为 Json 
值,所以参数必须是 [`TO_JSON`](./to-json.md) 支持的类型
+- NULL 会被转换为 Json 的 null, 如果不希望在数组中保留 null 值,可以使用函数 
[`JSON_ARRAY_IGNORE_NULL`](./json-array-ignore-null.md).
+- 如果参数类型不被 [`TO_JSON`](./to-json.md) 支持,那么会得到错误,可以先将该参数转换为 String 类型,比如:
+    ```sql
+    select JSON_ARRAY(CAST(NOW() as String));
+    ```
+    > NOW() 函数得到的是 DateTime 类型,需要通过 CAST 函数转换为 String 类型
+- 如果参数是 Json 字符串并且希望将其作为 Json 对象加入到数组中,应该显式调用 [`JSON_PARSE`](./json-parse.md) 
函数将其解析为 Json 对象:
+  ```sql
+  select JSON_ARRAY(JSON_PARSE('{"key": "value"}'));
+  ```
 
 ## 示例
-
-```sql
-select json_array();
-```
-
-```text
-+--------------+
-| json_array() |
-+--------------+
-| []           |
-+--------------+
-```
-
-```sql
-select json_array(null);
-```
-
-```text
-+--------------------+
-| json_array('NULL') |
-+--------------------+
-| [NULL]             |
-+--------------------+
-```
-
-```sql
-SELECT json_array(1, "abc", NULL, TRUE, CURTIME());
-```
-
-```text
-+-----------------------------------------------+
-| json_array(1, 'abc', 'NULL', TRUE, curtime()) |
-+-----------------------------------------------+
-| [1, "abc", NULL, TRUE, "10:41:15"]            |
-+-----------------------------------------------+
-```
-
-```sql
-select json_array("a", null, "c");
-```
-
-```text
-+------------------------------+
-| json_array('a', 'NULL', 'c') |
-+------------------------------+
-| ["a", NULL, "c"]             |
-+------------------------------+
-```
+1. 常规参数
+    ```sql
+    select json_array() as empty_array, json_array(1) v1, json_array(1, 'abc') 
v2;
+    ```
+    ```
+    +-------------+------+-----------+
+    | empty_array | v1   | v2        |
+    +-------------+------+-----------+
+    | []          | [1]  | [1,"abc"] |
+    +-------------+------+-----------+
+    ```
+2. NULL 参数
+    ```sql
+    select json_array(null) v1, json_array(1, null, 'I am a string') v2;
+    ```
+    ```
+    +--------+--------------------------+
+    | v1     | v2                       |
+    +--------+--------------------------+
+    | [null] | [1,null,"I am a string"] |
+    +--------+--------------------------+
+    ```
+3. 不支持的参数类型
+    ```sql
+    select json_array('item1', map(123, 'abc'));
+    ```
+    ```
+    ERROR 1105 (HY000): errCode = 2, detailMessage = Can not find the 
compatibility function signature: to_json(MAP<TINYINT,VARCHAR(3)>)
+    ```
+4. Map 类型参数可以先显式转换为 JSON
+
+    ```sql
+    select json_array(1, cast(map('key', 'value') as json));
+    ```
+    ```
+    +--------------------------------------------------+
+    | json_array(1, cast(map('key', 'value') as json)) |
+    +--------------------------------------------------+
+    | [1,{"key":"value"}]                              |
+    +--------------------------------------------------+
+    ```
+5. Json 字符串可以用 json_parse 解析

Review Comment:
   加一个不用json parse的例子,表示默认是把字符串当做字符串来处理的



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to