EasyCoder documentation


JSON commands

JSON commands allow a script to communicate with web servers, retrieve JSON-formatted data then process and display it. There is just one command keyword, which is qualified by what follows it.


The json command has a number of variants, as follows:

Get JSON data from a server

json get `variable` from `url`
Makes a call to {url} to retrieve data, which must be returned as a valid JSON string. It is placed into {variable} as text and can then be used directly or further processed using other json commands.

json get Response from `https://easycoder.software/ec/index.php?random=1&low=10&high=50`

Extract a property

json get item `name` of `source` as `target`
Extracts the property identified as {name} from variable {source} and places it in the variable {target}. {source} and {target} must both be variables but {name} can be a text string or a variable holding text.

json get item `username` of Customer as Name
json get item UserName of Customer as Name

Extract an array element

json get element {number} of {source} as {target}
Extracts element {number} of the JSON array {source} and places it in the variable {target}. {source} and {target} must both be variables but {number} can be a numeric value or a variable holding a number.

json get element `N` of Customers as Customer
json get item 32 of Customers as Customer

Set a variable to a JSON value

json set {target} from {source}
Sets up a HTML SELECT element with a list of items taken from the JSON object given, usually as returned by a json get command. The internal value of each OPTION is the same as the displayed value so this only works for lists of strings. Where the items are JSON objects you need to specify which property should be used as the display value, as in the second example below. See also property in Values.

json set List from Items
json set List from Items as `title`

(title is the property name)

Set the encoding method

json set encoding to {value}
Text values in JSON are all enclosed in double quotes, which causes problems if the content itself includes double quotes. New line characters also cause problems, so REST providers encode strings in one way or another, which means you have to know the encoding in order to decode. We currently support url (URL encoding, commonly used in PHP websites) or none (no encoding).

json set encoding to `url`
json set encoding to `none`

Shuffle a JSON array

json shuffle {array}
Shuffle the items in the array (put them in random order).

json shuffle Gallery