Description:
Parse a string, a record, a sequence or a table sequence of JSON format.
Syntax:
json(x)
Note:
If parameter x is a JSON string, the function parses it into a table sequence to return; if parameter x is a record, a sequence or a table sequence, the function parses it into a JSON string to return.
The format of JSON string is [{F:v,…},…], where v is the value of F and a string constant should be quoted.
Parameter:
x |
A JSON string/record/sequence |
Option:
@v |
Treat parameter x as an expression and calculate its result |
@t |
Arrange the returned result set as a same-structure table sequence |
Return value:
A record/sequence/table sequence/JSON string
Example:
|
A |
|
1 |
="{name:'China',province:[{name:'Heilongjiang',cities: {city:['Harbin','Daqing']}},{name:'Guangdong', cities:{city:['Guangzhou','Shenzhen','Zhuhai']}},{name:'Taiwan',cities: {city:['Taipei','Kaohsiung']}},{name:'Xinjiang',cities:{city:['Urumqi']}}]} " |
|
2 |
=json(A1) |
A1 is a JSON string, which is parsed into a table sequence and return the result: |
3 |
=demo.query("select EID,NAME,SURNAME from EMPLOYEE") |
|
4 |
=json(A3) |
A3 is a table sequence, which is parsed into a JSON string and return the result: |
5 |
="{ number:rand(10)}" |
|
6 |
=json(A5) |
Result: |
7 |
=json@v(A5) |
The @v option treats rand(10) as an expression and calculates it, and the function returns random numbers within 10 |
8 |
="[{ID:1,NAME:aa,GENDER:F},{GENDER:M,NAME:bb,ID:2}]" |
|
9 |
=json@t(A8) |
@t option enables arranging the result set as a same-structure table sequence |