FROM_JSON
Last updated
Was this helpful?
Last updated
Was this helpful?
The function FROM_JSON converts a to a value of an appropriate .
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.
null
null
boolean
true
number
3.141592653589793
string
"The quick brown fox"
array
[ 1, "two", 3 ]
object
{ "title": "Angels & Demons","author": "Dan Brown","isbn": "9781416524793","genres": ["Fiction"]}
object
{ "date": { "year": 2007, "month": 1, "day": 9 },"time": { "hour": 9, "minute": 41, "second": 0, "millisecond": 0 }, "timeZone": "America/Los_Angeles"}
object
{ "year": 2007, "month": 1, "day": 9}
object
{ "hour": 9, "minute": 41, "second": 0, "millisecond": 0}
object
{ "amount": 100, "code": "USD", "precision": 2}
json_string (required, type: string) A string containing valid JSON.
airscript_value (type: any) A value with the appropriate type given the contents of json_string.
Complex objects along with nested values will all be converted from JSON recursively.
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 .
A JSON string is enclosed in double quote characters and converts into a .
The FROM_JSON function is the opposite of the 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 , , , and . 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 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 for more details.