We Use Cookies

We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with this.

See our cookie policy.

Automation Action: Update JSON

Create or update multiple Json paths within Json text and return the updated Json to a variable.

Built-In Action

Update Json text. Create or update multiple Json paths within Json text and return the updated Json to a variable.

In the Existing Json entry, enter any valid json text or use a %variable% replacement containing Json. If this entry is blank a new Json document will be created.

You can now use the Set Paths grid to update specific Json paths. If the specified path already exists, it's value will be updated with the value in the Set To column. If the path does not exist it will be added.

Note: Paths are JsonPath format which uses dot notation and array indexes starting at zero (eg: name.Department). This differs from the Create Json and Read Json Document actions which use XPath notation.

The Set To column can contain fixed value or %variable% replacement or combination.

The Type column can be used to force the Json type at the specified path. If the Type is set to Auto or blank then the type will be automatically chosen based on the Set To value.

For example, suppose we have the following Json:


{
    "Name": "",
    "StartDate": "",
    "Age": 0,
    "Started": true,
    "Department": {
      "Name": "",
      "Manager": ""
    }
}              

If the Set Paths are set to:

Path Value Type
Name Nathan Walters String
StartDate %Msg_Date% DateTime
Age 30 Number
Department.Name Marketing String
Department.Manager Howard Williams String

The resulting Json would be returned as:


{
  "Name": "Nathan Walters",
  "StartDate": "2021-10-11T15:52:36Z",
  "Age": 30,
  "Started": true,
  "Department": {
    "Name": "Sales",
    "Manager": "Howard Williams"
  }
}              

If the Existing Json was blank it would be returned as:


{
  "Name": "Nathan Walters",
  "StartDate": "2021-10-11T15:56:53Z",
  "Age": 30,
  "Department": {
    "Name": "Sales",
    "Manager": "Howard Williams"
  }
}              

Since all the paths are new - and so all the Set Paths will be added.

Paths use dot notation to reference nested objects. You can also use [index] to reference specific array items (eg: object.nestedobject.array[1].value). Index numbers start at zero.

Paths are case sensitive.

Removing Paths

You can also use this action to remove paths from existing Json. In the Remove Paths grid enter the paths that you want to remove.

To remove individual array items the path must end with the index enclosed in square brackets (eg: object.array[1]). Array indexes start at zero. When removing multiple array items from the same array the index will change after each deletion. So to remove the first two array items you would set the Remove Paths to:


object.array[0] ' after this deletion the second item will be move to 0
object.array[0] ' so we need to delete zero again              

Assign To

Select the variable to receive the updated Json from the Assign To list. If the Compact option is enabled then the Json will be returned in compact format, otherwise it will be formatted and indented.