Application icon

Set Item in Container

This function is used to set an item referenced by the directed path. The directed path field can be an object element or an indexed array item. The path must end with .name or [index]]. examples:

object.name
object.list[4]
[2]

In the above indexed array items examples, the index must be greater or equal to zero and less that the number of items in the array. A special form of the index exists where the index can be preceded by an @ character. This implies insert at the specified index. When the @ form is used, the index can be equal to the number of items in the array and the statement is equivalent to an Add Item to Container Array statement (with more limited source types).

All text fields in the statement can contain any of the escape sequences defined in Escape Sequences.

The action test state will be set to true if there are no errors. The action test state will be false if any errors occurred. Named variable Container Error will contain the errror text. If the Stop action on error option is enabled, the action will be terminated with an error message in the case of an error.

You must select a data type to identify how the data field is formatted. The available data types are:

JSON Text
The JSON text is specified as being contained in a named variable or is directly entered in a resizable multi line edit panel. Note that only Array and Object items can be specified.

When using a named variable, the named variable field can contain any of the escape sequences defined in Escape Sequences. It is assumed that the named variable's content is properly formatted and escaped JSON text. This may be downloaded JSON returned by the Open URL statement.

When specifying JSON text directly you must select the Edit JSON button to edit the text in a resizable multi line edit panel. More information on this panel can be found here.

Referenced Item
The item path field contains a directed path to the item to be added. The added item is copied. Therefore any item can be added ... even the entire destination container.

Empty Array
This is equivalent to adding JSON Text with the json field set to []

Empty Object
This is equivalent to adding JSON Text with the json field set to {}

Null
A Null item is added.

Number
A Number item is added represented by the number in the number field. If the number field is empty, the item will be set to 0. Otherwise the data must resolve to be a number or the action test state will be set to false.

String
A String item is added represented by the possibly empty text in the string field.

Boolean
A Boolean item is added. If the boolean field is empty, the item will be set to false. The boolean field may contain true or false (case insensitive). Optionally an integer may be used to specify the value. 0 represents false and any other integer value represents true.

Pre-existing items are overwritten.

Example:

{
  "areaCodes" : [
    416,
    647,
    0
  ],
  "location" : {
    "place" : "unknown"
  }
}

Assume the above JSON is represented in a container named sample. The following statements...

Set the container item at 'sample.location.place' to string 'Toronto'
Set the container item at 'sample.location.province' to string 'Ontario'
Set the container item at 'sample.areaCodes[2]' to number '999'
Set the container item at 'sample.areaCodes[@0]' to string '???'

will result in the following:

{
  "areaCodes" : [
    "???",
    416,
    647,
    999
  ],
  "location" : {
    "place" : "Toronto",
    "province" : "Ontario"
  }
}


Containers

Directed Paths