JSON Syntax for Passing Parameters to Scripts

The JavaScript Object Notation (JSON) syntax contains a list of objects in brackets, colon separated with a key-value format.

Values can be:

  • Boolean, integer, real, floating point, strings in double quotes ("")
  • Array: ordered list of values, colon separated in square brackets ([])
  • Associative array : array in square brackets ([]) whose elements can be key-value couples, colon separated in curly brackets ({})
  • null

Note that it is possible to pass only one JSON whose proprieties are considered separated parameters. If deeper levels are available (as in the case of associative arrays) even though those levels are allowed, they are not considered parameters for the script.

The names of the parameters specified in the script may or may not be the same as those provided to the user. It the names are the same, they can be sorted differently from what specified in the script. If the names are not the same, they are sorted as provided to the user.

Examples

//The script is executed with a parameter, let's say "input"

 

read(input, "value")

 

If the script is invoked passing the object "System1:View:View.object" as parameter, the read operation (as defined in the script) is executed on the object provided. If you change the parameter, you change the object on which the operation will be executed.

 

    //The script is executed with a parameter, let's say "choice"

 

    if (choice === "read") {

        read(...)

    }

    else if (choice === "execute") {

        executeCommand(....)

    }

 

If the script is invoked by passing the "read" string, the read operation will be executed; if the "execute" string is passed, a command will be executed.

 

    console("a: " + a + "; b: " + b);

 

    parameter specified

    { "a": "value of a", "b": "value of b" }

 

This script will write in the Console expander the following string: a: value of a; b: value of b. The output in the Console expander is the same also with shuffled inputs. If the keys defined in the JSON do not match with the parameters names, the parameters will be provided in ordinal sorts. See the following example:

 

    console("a: " + a + "; b: " + b);

 

    parameter specified

    { "b": "value of b", "a": "value of a" }

 

For the JSON input { "b": "value of b", "a": "value of a" } the output in the Console expander is: c: value of b; d: value of a.

 

    ...

    //Do Something

    ...

 

    //parameter specified

    {

        "a": "value of a",

        "b": [

                {"c": "value of c"},

                {"d": "value of d"}

            ]

    }

 

    //that is

 

    { "a": "value of a", "b": [{"c": "value of c"}, {"d": "value of d"}]}

 

In the above example, only one JSON is passed as parameter (The Script Engine considers a and b as separate parameters. Furthermore, b contains an array, which means that it is possible to use b.c construct in the script with value c while construct b.d with value d.