Add or update key value pair in JSON Object UiPath

A lot of times while doing API automation or dealing with JSON data as input or output for the business process.

Sometimes we need to add some new key-value pairs or update key-value pairs in the JSON object.

Let’s say we are getting JSON object as input and after processing the data you might need to add a new key-value pair stating the status of the transaction.

Where you need to add a new key-value pair to that JSON object.

In the same example mentioned above this time we already have a status key but this time we need to update the value which is in the JSON object.

In this article, we will see how we can achieve this using UiPath:

Let’s get into the practical implementation of this task:

Adding new key-value pair to JSON object:

Step1: The input JSON object that we are using for this example is shown below:

json data uipath

The input that we are using here is a JSON object and we will see how we can add a new key-value pair to this JSON object.

After processing the above JSON object we need to add a new key called Result.

Step2: Drag and Drop Invoke method activity from activities panel to designer panel as shown below:

add or update key value pair

Here:

  • TargetObject – Provide your JSON object variable value.
  • MethodName – As we are adding the new object to the existing object mention Add.

Let’s look at the parameters that are required for adding new object:

add or update key value pair

Here it requires two parameters and they are mentioned below:

  • First Parameter – Provide the object key name here.
  • Second Parameter – Provide the object value here.

In this example, we are adding a result key and value to the existing JSON object.

Step3 – After adding a new object to the existing JSON object that looks like below:

json data uipath

Updating the key value in JSON object:

In this example we will update the existing key value in the JSON object that is given above:

Step1; Drag and Drop assign activity from activities panel to designer panel as shown below:

add or update key value pair

Here:

  • To – Provide the key-value where you want to update the key value. (eg: JsonOutput(“Status”))
  • Value – Provide the value that needs to be updated.

Step2: The updated JSON object looks like below:

json data uipath

This is how we add or update the key-value pair of JSON object using UiPath.

Happy Learning!

Like this post then let your friends know about this-:

Leave a Reply

Your email address will not be published. Required fields are marked *