cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

JSON Iterating through an Array for specific values

Hi all, I'm trying to output just the 'answer' values that are found under 'subquestion' at the JSON here: https://gist.githubusercontent.com/alexgmartin/18c78881bdddcaee36743833cec36721/raw/1500bc78002cd798...

 

I can ParseJSON and convert that Body to an array variable. But I don't know how to iterate through the array just to extract the values for 'answer'. Any help would be appreciated.

3 REPLIES 3
JohnAageAnderse
Memorable Member
Memorable Member

Hello @Anonymous 

 

My guess is that your array has one item and in that one item is a another array - the "data" - which contains all the survey data.

 

You will have to loop (apply to each) through both your one item and your "data" arrays. The inner loop (apply to each) for the "data" array will allow you to access the questions/answers. 

Getting the first question and answer: item()?['survey_data']?['19']?['subquestions']?['20']?['question'] and item()?['survey_data']?['19']?['subquestions']?['20']?['answer']

 

This you have to do for all your subquestions in the "data" using their respective paths!

Hope this helps you on the way 🙂

Kind regards, John

Anonymous
Not applicable

@JohnAageAnderseIs there a way I can loop through it without specifying the ['19'] or ['20']? Something like iterate through all child elements..I dunno:/

Hello @Anonymous 

 

Did you find a solution for this yet? Anyway I found that using a Select action, it is possible to create an object with the questions and answers for easy use.

With your JSON data element as input (From) to a Select action, you can then map each question and answer.

JSON.Select.Map.jpg

Each map needs a name (the question) and a value (the answer), so using expressions in both name and value field as follows:

Name expression: item()?['survey_data']?['19']?['subquestions']?['20']?['question']

Value expression: item()?['survey_data']?['19']?['subquestions']?['20']?['answer']

This you do for all the questions/answers that you need.

 

Note that under element "77", some of the questions are the same as under element "19", so I added "Contact " before the expression to avoid naming conflicts!

Hope the above helps you 🙂

Kind regards, John

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Users online (2,187)