Is it possible to add conditional statement in JSON payload?

Hi all,

Wanted to know if we can add conditional statement inside json payload?

Thanks in advance…

@Manisha24,

Share some sample how you want it.

Thanks,
Ashok :slight_smile:

I have one json payload as:
{
id: “123”,
name: “test”,
dob : “1999-9-9”
education:[
{
class : “X”,
schoolname: “random”
},
{
degree: “some”,
college: “test”
},
{
designation : “trainer”,
employer : “abc”
}
]
place : “test”
}

regarding education field : If person’s age less than 16 then I want to input only school details. If it is in betwwen 16 and 22 then i want to input both school and college. if age is grater than 22 then I want to input all the fields. Is it possible to add condition in json payload without adding condition outside of this json payload?

@Manisha24,

In JSON, you cannot directly embed conditions or logic because JSON is a data format, not a programming language. However, you can process and modify the JSON data according to the conditions in UiPath or any other programming environment.

Here’s how you can handle this in UiPath Studio:

  1. Deserialize the JSON: Use the Deserialize JSON activity to convert the JSON string into a JObject so you can manipulate it.
  2. Calculate the Age: Extract the date of birth (DOB) from the JSON, convert it to a DateTime object, and calculate the person’s age.
  3. Conditionally Modify the JSON: Based on the calculated age, you can modify the education field of the JObject.
  4. Serialize the JSON: Once you’ve made the necessary modifications to the JSON object, you can serialize it back into a JSON string.

Thanks,
Ashok :slight_smile:

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.