Hwo to create a custom json using Dictionary modules?

HI team,

i am working on sentiment analysis use case . where i need to send a json to that api . I have the content in datatable . example 30 rows are there.

i need to create 30 key value pair in this special format.

Json format


{
“documents”: [
{
“language”: “en”,
“id”: “1”,
“text”: “Hello world. This is some input text that I love.”
},
{
“language”: “en”,
“id”: “2”,
“text”: “It’s incredibly sunny outside! I’m so happy.”
}
],
}


i thought of using while loop and using add to dictionary activity to add the row ,

but i need to have one json and that to in this format and need to pass that as body to that post api.

any suggestions?

Hi @Abhinavpandey,

  • Import Newtonsoft.Json
  • Use assign activity to convert datatable to JSON string
    jsonString = JsonConvert.SerializeObject(datatable)
  • Then add the parent node ‘documents’ using string concatenation
1 Like

thanks @aanandsanraj

understood the first 3 points
but 4th one "Then add the parent node ‘documents’ using string concatenation"

this i am not understanding.

can you sugget here?
i have count of no. of rows in datatable.
i created a variable using assign activity i.e DT_to_Json of string type

@Abhinavpandey

Check this xaml
test.xaml (9.0 KB)

2 Likes

thanks @aanandsanraj.
Its works fine

Just wanted to clear my concept.

please correct me if i understood it in wrong way

JsonConvert.SerializeObject(dtt) : to have the the datatable in Json format

JArray.Parse : to have that json in array containing all json (all the rows of that datatable )

var.Add(“documents”, arr) : to add main key "document on top of that array

then again JsonConvert.SerializeObject(out argumentof invoke ) to have main json

Yeah you are correct.

1 Like

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