Skip to content

Commit e5fc7a5

Browse files
committed
add some doc
Signed-off-by: xinyual <xinyual@amazon.com>
1 parent f444398 commit e5fc7a5

1 file changed

Lines changed: 106 additions & 2 deletions

File tree

docs/user/ppl/functions/json.rst

Lines changed: 106 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ JSON
4141
Description
4242
>>>>>>>>>>>
4343

44-
Usage: `json(value)` Evaluates whether a string can be parsed as a json-encoded string and casted as an expression. Returns the JSON value if valid, null otherwise.
44+
Usage: `json(value)` Evaluates whether a string can be parsed as a json-encoded string. Returns the value if valid, null otherwise.
4545

4646
Argument type: STRING
4747

48-
Return type: BOOLEAN/DOUBLE/INTEGER/NULL/STRUCT/ARRAY
48+
Return type: STRING
4949

5050
Example::
5151

@@ -60,3 +60,107 @@ Example::
6060
| json scalar string | "abc" | "abc" |
6161
| json empty string | | null |
6262
+---------------------+---------------------------------+-------------------------+
63+
64+
JSON_OBJECT
65+
----------
66+
67+
Description
68+
>>>>>>>>>>>
69+
70+
Usage: `json_object(key1, value1, key2, value2...)` create a json object string with key value pairs. The key must be string.
71+
72+
Argument type: key1: STRING, value1: ANY, key2: STRING, value2: ANY ...
73+
74+
Return type: STRING
75+
76+
Example::
77+
78+
> source=json_test | eval test_json = json_object('key', 123.45) | head 1 | fields test_json
79+
fetched rows / total rows = 1/1
80+
+-------------------------+
81+
| test_json |
82+
|-------------------------|
83+
| {"key":123.45} |
84+
+-------------------------+
85+
86+
JSON_ARRAY
87+
----------
88+
89+
Description
90+
>>>>>>>>>>>
91+
92+
Usage: `json_array(element1, element2, ...)` create a json array string with elements.
93+
94+
Argument type: element1: ANY, element2: ANY ...
95+
96+
Return type: STRING
97+
98+
Example::
99+
100+
> source=json_test | eval test_json_array = json_array('key', 123.45) | head 1 | fields test_json_array
101+
fetched rows / total rows = 1/1
102+
+-------------------------+
103+
| test_json_array |
104+
|-------------------------|
105+
| ["key",123.45] |
106+
+-------------------------+
107+
108+
JSON_ARRAY_LENGTH
109+
----------
110+
111+
Description
112+
>>>>>>>>>>>
113+
114+
Usage: `json_array_length(value)` parse the string to json array and return size, if can't be parsed, return null
115+
116+
Argument type: value: STRING
117+
118+
Return type: INTEGER
119+
120+
Example::
121+
122+
> source=json_test | eval array_length = json_array_length("[1,2,3]") | head 1 | fields array_length
123+
fetched rows / total rows = 1/1
124+
+-------------------------+
125+
| array_length |
126+
|-------------------------|
127+
| 3 |
128+
+-------------------------+
129+
130+
> source=json_test | eval array_length = json_array_length("{\"1\": 2}") | head 1 | fields array_length
131+
fetched rows / total rows = 1/1
132+
+-------------------------+
133+
| array_length |
134+
|-------------------------|
135+
| null |
136+
+-------------------------+
137+
138+
JSON_EXTRACT
139+
----------
140+
141+
Description
142+
>>>>>>>>>>>
143+
144+
Usage: `json_extract(json_string, path1, path2, ...)` it first transfer json_string to json, then extract value using paths. If only one path, return the value, otherwise, return the list of values. If one path cannot find value, return null as the result for this path. The path use "{<index>}" to represent index for array, "{}" means "{*}".
145+
146+
Argument type: json_string: STRING, path1: STRING, path2: STRING ...
147+
148+
Return type: STRING
149+
150+
Example::
151+
152+
> source=json_test | eval extract = json_extract('{\"a\": [{\"b\": 1}, {\"b\": 2}]}', 'a{}.b') | head 1 | fields extract
153+
fetched rows / total rows = 1/1
154+
+-------------------------+
155+
| test_json_array |
156+
|-------------------------|
157+
| [1,2] |
158+
+-------------------------+
159+
160+
> source=json_test | eval extract = json_extract('{\"a\": [{\"b\": 1}, {\"b\": 2}]}', 'a{}.b', 'a{}'') | head 1 | fields extract
161+
fetched rows / total rows = 1/1
162+
+---------------------------------+
163+
| test_json_array |
164+
|---------------------------------|
165+
| [[1,2],[{\"b\": 1}, {\"b\": 2}]]|
166+
+---------------------------------+

0 commit comments

Comments
 (0)