json()

Read(2293) Label: json string, record, parse,

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:

Record/Sequence/Table sequence/JSON string

Example:

Parse a JSON string as a table sequence and return it:

 

A

 

1

=file("user.txt").read()

Return a JSON string as follows:

2

=json(A1)

Parse A1’s JSON string as a table sequence and return it:

 

Parse a table sequence as a JSON string and return it:

 

A

 

1

=demo.query("select top 5 EID,NAME,SURNAME from EMPLOYEE")

Return a table sequence:

2

=json(A1)

Parse A1’s table sequence as a JSON string and return it:

 

When @v option works:

 

A

 

1

="{number:rand(10)}"

 

2

=json(A1)

Return result as follows:

3

=json@v(A1)

@v option works to treat rand(10) as an expression and compute it; and the function returns a number within 10 randomly.

 

When @t option works:

 

A

 

1

="[{ID:1,NAME:aa,GENDER:F},{GENDER:M,NAME:bb,ID:2}]"

 

2

=json(A1)

Return result as follows:

3

=json@t(A1)

@t option works to arrange the result set as a same-structure table sequence: