jsonParse
jsonParse ( jsonString : string , type : integer {, *} ) : any
Parameter | Type | Description | |
---|---|---|---|
jsonString | string | → | JSON string to parse |
type | integer | → | Type in which to convert the values |
* | → | Adds line position and offset of each property if returned value is an object | |
Result | any | ← | Values extracted from JSON string |
Description
The jsonParse
command parses the contents of a JSON-formatted string and extracts values that you can store in a Qodly field or variable.
In jsonString
, pass the JSON-formatted string whose contents you want to parse. This string must be formatted correctly, otherwise a parsing error is generated. jsonParse
can therefore be used to validate JSON strings.
If you use pointers, you must call the jsonStringify
command before calling jsonParse
.
By default, if you omit the type parameter, Qodly attempts to convert the value obtained into the type of the variable or attribute used to store the results (if one is defined). Otherwise, Qodly attempts to infer its type. You can also force the type interpretation by passing one of the following constants in the type parameter:
Constant | Type | Value |
---|---|---|
kBoolean | integer | 6 |
kCollection | integer | 42 |
kDate | integer | 4 |
kInteger | integer | 9 |
kObject | integer | 38 |
kNumber | integer | 1 |
kString | integer | 2 |
kTime | integer | 11 |
If you pass the *
optional parameter and if the jsonString
parameter represents an object, the returned object contains an additional property named __symbols
that provides path, line position, and line offset of each property and sub-property of the object. This information can be useful for debugging purposes. The structure of the __symbols
property is:
__symbols:{//object description
myAtt.mySubAtt...:{ //property path
line:10, //line number of the property
offset:35 //offset of the property from the beginning of the line } }
The *
parameter is ignored if the returned value is not of the object type.