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”
}
},
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 :
replace all the double quotes with single quotes
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’
}
}}}”
Get the required array of options using above
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”)