Build Json Array from scratch and pass that array to Json Object

Hi ,

I need a help in creating json array from scratch using assign activity and pass that jarray value to a json object.

Value passing in jarray is dynamic.

Sample -
“defaultref”:[
{
“Type”:“A”,
“Subsidy”:{
“ID”:“123456”,
“Name”:“Rahul”
}
},
{
“Type”:“B”,
“Subsidy”:{
“ID”:“1298456”,
“Name”:“Rai”
}
}
]

Can you please help me in creating this.

Thank you!!

You need to create the custom activity
Note : this is sample file you need to change as per your need

C# code for creating a JSON array with dynamic values and assigning it to a JSON object:

using Newtonsoft.Json;

public class Subsidy { public string ID { get; set; } public string Name { get; set; } }

JArray defaultRefArray = new JArray();
List<Dictionary<string, string>> dataList = // Your dynamic data source

foreach (var item in dataList)
{
    JObject subsidyObject = new JObject(new JProperty("ID", item["ID"]), new JProperty("Name", item["Name"]));
    JObject mainObject = new JObject(new JProperty("Type", item["Type"]), new JProperty("Subsidy", subsidyObject));
    defaultRefArray.Add(mainObject);
}

JObject finalObject = new JObject(new JProperty("defaultref", defaultRefArray));

string jsonString = JsonConvert.SerializeObject(finalObject);

This code achieves the same functionality but removes unnecessary explanations. You can integrate this code into your UiPath workflow using an “Assign” activity as described previously.

@mukesh.singh thank you …it works for me

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