FROM_JSON
The function FROM_JSON converts a JSON String to a value of an appropriate variable type.
All Airkit types can be converted to and from JSON in such a way that serializing to JSON, and deserializing that JSON will return the original value. The following table lists how each data type is encoded as JSON.
Airkit Variable Type | JSON type | Example |
---|---|---|
null | null | |
boolean | true | |
number | 3.141592653589793 | |
string | "The quick brown fox" | |
array |
| |
object |
| |
object |
| |
object |
| |
object |
| |
object |
|
Declaration
Parameters
json_string (required, type: string)
A string containing valid JSON.
Return Values
airscript_value (type: any)
A value with the appropriate type given the contents of json_string.
Examples
FROM_JSON will automatically convert from a JSON type to an Airkit type. For example, a string containing a JSON number will be converted into a Number.
A JSON string is enclosed in double quote characters and converts into a String.
Complex objects along with nested values will all be converted from JSON recursively.
Discussion
The FROM_JSON function is the opposite of the TO_JSON function. The most common use for the FROM_JSON function is to parse data received from an external system. There are a few subtleties in accepting data that may contain values of the type DateTime, Date, Time, and Currency. It is very unlikely that the external system will represent these types the same way they are represented in Airkit, therefore, additional processing may be needed.
External systems will commonly represent DateTimes as either a number or as a String, commonly referred to as a timestamp. Airkt provides support for working with this common encoding technique, see Working with Date, Time & DateTime in Airscript for more details.
Last updated