cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
dignus93reply
Frequent Visitor

Iterate through a Json array?

Hello there,

 

I have a Json structure like that

 


[
 {
  "ColumnID": "1",
  "Column1": "Main directory1",
  "Column2": "Sub directory1",
  "Column3": "Documents1",

 },

 {
  "ColumnID": "2",
  "Column1": "Main directory2",
  "Column2": "Sub directory2",
  "Column3": "Documents2",

 },

 {
  "ColumnID": "3",
  "Column1": "Main directory3",
  "Column2": "Sub directory3",
  "Column3": "Documents3",

 },
]

 


I would like to iterate through it so that at each iteration I read the following values:
First iteration: Main directory1
Second iteration: Main directory2
Third iteration: Main directory3


What I did until now? I declared a variable iteratorRow that starts from 1, I filter the array to get the #iteratorRow location, I compose it to get the single array (and not the object), I compose it again to get the single value.

This flow is working if I am not using "Do until" and I want to get a single value of the Json array.

 

image.png

 

 

The big problem is the "Step1 Filter array" action. It can not get a variable on the right, it must be a string. This is driving me insane.
-I try to edit in advance mode like this: "@equals(item()?['ColumnID'], variables('iteratorRow'))" but nothing.
-I try to build a string with the value of iteratorRow and then concat a series of variable to have something like this @equals(item()?['ColumnID'], 'theActualIteratorRow'  but I cant pass a variable in advance edit.

Do you have a solution or workaround to this problem? 

1 ACCEPTED SOLUTION

Accepted Solutions
dignus93reply
Frequent Visitor

Thanks for all the good advice folks.

 

I solved like this: I declare the json array in a string variable. I parse it in Json. In the parse JSON action I click "generate from sample" and I paste the json array. It will generate automatically a schema. Then I loop through it with an Apply to each. In the "select an output from previous steps" of the apply to each I chose the Body of the parse JSON. Inside I read the Column1.

 

Finally I can get my desired output
"Main directory1" at iteration1;

"Main directory2" at iteration2;

"Main directory3" at iteration3

s1.png

 

View solution in original post

6 REPLIES 6
jinivthakkar
Dual Super User
Dual Super User

@dignus93reply I found a similar thread here :

 

https://powerusers.microsoft.com/t5/Building-Flows/Convert-JSON-array-to-string-array/m-p/395040

 

https://powerusers.microsoft.com/t5/General-Power-Automate/For-each-sum-JSON-array/m-p/557499

 

 

--------------------------------------------------------------------------------

If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.

mahoneypat
Dual Super User
Dual Super User

Why not just use an Apply To Each on your array instead of Do Until?

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about the Power Platform, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


dignus93reply
Frequent Visitor

Thanks for all the good advice folks.

 

I solved like this: I declare the json array in a string variable. I parse it in Json. In the parse JSON action I click "generate from sample" and I paste the json array. It will generate automatically a schema. Then I loop through it with an Apply to each. In the "select an output from previous steps" of the apply to each I chose the Body of the parse JSON. Inside I read the Column1.

 

Finally I can get my desired output
"Main directory1" at iteration1;

"Main directory2" at iteration2;

"Main directory3" at iteration3

s1.png

 

holy smokes @dignus93reply you just saved me from the counter-variable apocalypse!

I did exactly what you said and now I am able to fully parameterize files using Parse JSON and no counters!

Thanks brother, I owe you one👆

HEATFreight
Super User
Super User

Yo @dignus93reply, just to update you on my progress... I am now nesting Parse JSON actions within each other to parametrically grab specific attributes and populate them into arrays for later processing, all thanks to your solution!

The more I think about it, the more I think nesting them may be unnecessary, because by it's very nature the Parse JSON action should make all of the properties accessible if the right schema is used, but it's not always easy to code working logic with such a massive set of dynamic content, so a nested pair of Parse JSON actions has proven extremely powerful in my use case, and it would not be possible without your little trick!

ChrisMendoza
Resolver IV
Resolver IV

@dignus93reply- I know I'm late to the party here however, I had a similar need and I solved as:

items('Apply_to_each')?['Column1']

 

image.png

image.png

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

May UG Leader Call Carousel 768x460.png

June User Group Leader Call

Join us on June 28 for our monthly User Group leader call!

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Power Automate Designer Feedback_carousel.jpg

Help make Flow Design easier

Are you new to designing flows? What is your biggest struggle with Power Automate Designer? Help us make it more user friendly!

Users online (9,167)