Like most of Construct JSON arrays use zero-based indices, so the path array.0
refers to the first element (123) and array.1
refers to the second element (456), and so on.
Relative paths
The Set path action changes the current path, making it more convenient to access deeply nested keys. A relative path can then be used to continue from the current path. Relative paths begin with a dot, e.g. .bar
. If a path does not begin with a dot, it is always treated as absolute (starting from the root), regardless of the current path.
For example suppose you want to access multiple keys under a common path, like foo.bar.baz.first
and foo.bar.baz.second
. You can first use Set path to set foo.bar.baz
as the current path, and then the paths .first
and .second
refer to foo.bar.baz.first
and foo.bar.baz.second
respectively. Even with a current path set, the path abc.def
refers to top-level keys because it does not start with a dot, so is treated as absolute.
The For each looping condition also sets the current path to the full path to the current key being iterated, making it convenient to retrieve data in a loop.
JSON conditions
- Compare type
- Test the type of a value at a given path. This can also detect the special
null
value that cannot be returned in a Construct expression, as well as identifying arrays and objects.
- Compare value
- Compare the value at a given path. This can only be used with number or string values.
- For each
- Repeats once for each key at a path in the JSON data. This can be used with either object or array types; in the case of arrays, the keys are the array indices (e.g. 0, 1, 2...) represented as a string. Inside the loop, the current path is set to the current key being iterated, so relative paths can be used to retrieve data from the current key. The CurrentKey, CurrentValue and CurrentType expressions return information about the current key-value pair being iterated.
- Has key
- Determine if a key exists at a given path.
- Is boolean set
- Determine if a given path contains a boolean "true" value.
- On parse error
- Triggered after a Parse action if there was invalid syntax in the JSON string resulting in an error trying to parse it.
JSON actions
Note that when setting values, nonexistent keys are created as necessary. For example if the JSON file is empty but you set the number 5 at the path foo.bar
, the foo
and bar
keys are automatically created, resulting in the data { "foo": { "bar": 5 } }
.
- Delete key
- Delete the key at a path so it is no longer present in the JSON data.
- Parse
- Parse a string of JSON data and load it in to the object so it can be accessed.
- Pop value
- Remove an element at the start or end of an array located at a path. If the path does not specify an array, this does nothing.
- Push value
- Add an element with the given value at the start or end of an array located at a path. If the path does not specify an array, this does nothing.
- Insert value
- Inserts an element with the given value into an array located at a path, increasing the size of the array by 1. The element is inserted at a specified index, if any elements existed at or after that index they pushed forward by 1.
- Remove values
- Removes a specified number of elements from an array located at a path, reducing the size of the array. Elements are removed starting at a specified index, if there are less elements after the array than requested to be removed then only the available number will be removed.
- Set array
- Create an array with a given number of elements at a path. If an array already exists at the given path, it is resized to the given number of elements. In both cases, any new elements are initialised to 0.
- Set boolean
- Set a true or false value at a path.
- Set JSON
- Parse a string of JSON data, and set the value at a path to the resulting JSON. This is useful to merge data from different sources in to the same JSON object.
- Set null
- Set the special
null
value at a path.
- Set object
- Set an empty object at a path. If there is already an object at the given path, it is replaced with an empty object.
- Set path
- Set the current path. This allows relative keys to continue from this path.
- Set value
- Set a number or string value at a path.
- Toggle boolean
- Toggle a boolean value at a path. If the value at the path is not a Boolean, do nothing.
- Add to
- Add a value to the numerical value at a path. If the value at the path is not numerical, do nothing.
- Subtract from
- Subtract a value from the numerical value at a path. If the value at the path is not numerical, do nothing.
JSON expressions
- ArraySize
- Return the length of an array at a path. If there is not an array at the given path, returns -1.
- Back
- Front
- Return the element at the start (front) or end (back) of an array at a given path. If there is not an array at the given path, returns -1.
- CurrentKey
- In a For each loop, a string of the current key name. If an array is being looped, the current key is a string of the current index, e.g. "0", "1"...
- CurrentType
- In a For each loop, a string representing the type of the current value, which can be one of
"null"
, "array"
, "object"
, "boolean"
, "number"
or "string"
.
- CurrentValue
- In a For each loop, the current value. This only returns numbers or strings, or booleans as a number (0 for false and 1 for true). All other types will return 0.
- Get
- Get the value at a given path. The path can be relative to the current path or the current key in a For each loop. This only returns numbers or strings, or booleans as a number (0 for false and 1 for true). All other types will return 0.
- Type
- Get a string representing the type of a value at a given path, which can be one of
"null"
, "array"
, "object"
, "boolean"
, "number"
or "string"
. The path can be relative to the current path or the current key in a For each loop.
- Path
- Return the current path.
- ToBeautifiedString
- ToCompactString
- Return the current JSON data either as a formatted string with line breaks and indentation ("beautified"), or as a minimal string excluding any line breaks or indentation ("compact"). Beautified strings are easier to read, but compact strings are more efficient for storing, sending over the Internet, and loading. Both beautified and compact strings always represent identical data, and there are a range of third-party tools available that can convert between beautified and compact representation.
- GetAsBeautifiedString
- GetAsCompactString
- Return the JSON data at a specified location either as a formatted string with line breaks and indentation ("beautified"), or as a minimal string excluding any line breaks or indentation ("compact"). These expressions are conceptually similar to "ToBeautifiedString" and "ToCompactString" respectively, but for a specific part of the current data instead of everything. In that way they are the opposite half of the "Set JSON" action, which allow you to set a value from a JSON string at a given location.