JSON integration with UIPath

Below is a sample JSON.
Could anyone help me with the iteration through JSON,

for e.g. i want the result " Huston Rocket " so how could i do that . I have used for each in UIpath .

Any better way to do this ?

{
“quiz”: {
“sport”: {
“q1”: {
“question”: “Which one is correct team name in NBA?”,
“options”: [
“New York Bulls”,
“Los Angeles Kings”,
“Golden State Warriros”,
“Huston Rocket”
],
“answer”: “Huston Rocket”
}
},

2 Likes

Kindly have a view on this buddy

Cheers @shikharno.7

1 Like

You can get the options array using this @shikharno.7,

To get answer key : data.Root(“quiz”).Item(“sport”).Item(“q1”).Item(“answer”)

To get options array :
data.Root(“quiz”).Item(“sport”).Item(“q1”).Item(“options”)

But your JSON is not in the correct format, some closing roots are missing and , here are the steps to do :

  1. replace all the double quotes with single quotes
  2. Use deserialize JSON activity and paste the json below :

“{
‘quiz’: {
‘sport’: {
‘q1’: {
‘question’: ‘Which one is correct team name in NBA?’,
‘options’: [
‘New York Bulls’,
‘Los Angeles Kings’,
‘Golden State Warriros’,
‘Huston Rocket’
],
‘answer’: ‘Huston Rocket’
}
}}}”

  1. Get the required array of options using above
  2. Assign it to array type variable and get the required using array[3] as it is in the 4 index…

or simply if you have answer everytime in your JSON …

Use this : data.Root(“quiz”).Item(“sport”).Item(“q1”).Item(“answer”)

1 Like

@HareeshMR , @Palaniyappan
Thank you for the prompt response.
I also tried this method .

Could this be solved with some other logic too ? like linkquery

Fine
hope this would help you

Cheers @shikharno.7

1 Like

Can you explain a bit more?

Using this, you will get the required directly and I don’t understand what you mean by linkquery?

@HareeshMR , looking for an answer somewhat similar to what @Palaniyappan quoted.

There are good number of JSON formatter and verifying tools online

Here is an example JSON flow. It uses a JSON file downloaded form a Football Stats website.

The intention is to extract the home team from the first game. This is done by accessing each branch of the JSON:

Trim(jo_MatchInfo("matches")(1)("homeTeam").ToString)

Hopefully this helps.

JSON.SimpleExample.zip (2.9 KB)