How can I read data from excel cells and use that to build my json structure

I have an excel sheet which has data and I need UIPath to pass few selective data into a JSON file. How is this possible?

I assume you know how to read your data from Excel.

1/ Make sure you import Newtonsoft.Json namespace
image

2/ Create variable of type Newtonsoft.Json.Linq.JObject, e.g. objJson
image

3/ Initialize the variable using Assign activity
objJson = new JObject

4/ Add values from your Excel to the Json variable using Assign activity
objJson(“attribute1”) = “Attribute1Value”
objJson(“attribute2”) = “Attribute2Value”

5/ Save Json variable to file using “Write text file” activity
image

Resulting file:
{
“attribute1”: “Attribute1Value”,
“attribute2”: “Attribute2Value”
}

Cheers

2 Likes

Thanks, this worked.
There is another possibility for json like this which needs to be constructed from the excel data

{
“id”: “someid”,
“number”:“somenumber”,
“data”:{
“bio”:“somebio”,
“operation”:“someoperation”
}
}

Any suggestions on how I could get this done using the data from excel please?

Like this:

objJson = New JObject(
New JProperty("id","someid"),
New JProperty("number","somenumber"),
New JProperty("data",
  New JObject(
     New JProperty("bio","somebio"),
	 New JProperty("operation","someoperation")
	 )
   )
 )

For more info look here:

1 Like

Thanks mate! :slight_smile: :100:

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