asJson
Converts a JSON string to a JSON object.
For more about JSON data, see http://json.org/index.html and the Describing a JSON object tutorial.
Parameters
INPUT (string)
The string to convert. This must be wrapped in single quotation marks and contain no blank spaces. Keys and values must be wrapped in double quotation marks.
Examples
This example uses the following JSON string:
'{"Monday":"lundi","Tuesday":"mardi","Wednesday":"mercredi"}'
The keys are the first three days of the week written in English, and the values are the same days written in French. Think of this JSON string as a (very) small English–French dictionary.
You might convert this string to a JSON object as part of a user-defined function. For example:
#value translateToFrench(input)
[[
dictionary = asJson('{"Monday":"lundi","Tuesday":"mardi","Wednesday":"mercredi"}')
hasKey(dictionary, input) ? dictionary[input] : 'no translation found'
]]
This creates a user-defined function called translateToFrench
, which takes one parameter (input)
. Note how the first line in the function body uses asJson
to convert the string to a JSON object. This creates an object with three key–value pairs. The keys are Monday, Tuesday, and Wednesday. The values are the days in French.
This is a user-defined function, so you must call it in a different script. For example:
ATL in Script | Result |
---|---|
| lundi |
| mardi |
| mercredi |
| no translation found |