cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
drake
Advocate II
Advocate II

How do you loop through JSON objects with Power Automate Desktop?

We are using the Invoke Web Service action to retrieve some json, but when we go to loop through the list of items in the json, it doesn't work.  Currently, we are doing this:

 

1) Using the Convert JSON to custom object to turn out json string into a workable object.

2) Using the Add item to list action to add the custom object from step #1 to a new list

3) Using a For each loop to parse the new list, but the conversion to list (step #2) seems to fail to break up the json into separate items, but instead the list just has one massive item (all of the json).

 

Any idea on how to loop through json with Power Automate Desktop?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
drake
Advocate II
Advocate II

We resolved this issue by referencing the collection in the loop.  It seems that we were at first, but figure out needed syntax.  

View solution in original post

7 REPLIES 7
drake
Advocate II
Advocate II

We resolved this issue by referencing the collection in the loop.  It seems that we were at first, but figure out needed syntax.  

dt_rpa
Regular Visitor

can u pls give examples?  I need to see the formatting. thx in adv

where have you resolved I have the same issue 

We are using the Invoke Web Service action to retrieve some json, but when we go to loop through the list of items in the json, it doesn't work.  Currently, we are doing this:

 

1) Using the Convert JSON to custom object to turn out json string into a workable object.

2) Using the Add item to list action to add the custom object from step #1 to a new list

3) Using a For each loop to parse the new list, but the conversion to list (step #2) seems to fail to break up the json into separate items, but instead the list just has one massive item (all of the json).

 

Any idea on how to loop through json with Power Automate Desktop?

cprima
New Member

Hello,

 

stuck at the same step, currently evaluating Microsoft's LowCode offering in my job. Testing a few standard usecases and support channels.

 

Task: Retrieve data from webservice and persist in csv.

Attempted solution: 

76pJkll

 

 

Error: Variable 'JsonAsCustomObject' must be a list, datatable or datarow.

 

 

Is there actually any useful implementation in Power Automate Desktop for consuming/processing a custom object? The screenshots in Power Automate Desktop Extract null from JsonAsCus... - Power Platform Community (microsoft.com) seem to suggest it should work!?

Here is what we did to make this work:

1) Invoke Web Service

2) Convert JSON to custom object

3) For each on the custom object (be sure to reference the collection inside the object if there is this is a separate part).

After many hours of trial and error and reading everything I could find on the matter, I believe I got what is going on.

 

If the json collection you are trying to iterate is not an index based array, you cannot iterate using Power Automate Desktop loop functions. You will get an error like this: "it's only possible to iterate a list, datatable or datarow."

 

On the other hand, if the json collection is index based, you will be able to use loops (ex. "foreach") to iterate each entry.

 

Example of an index based json collection:

 

{
   "vulnerabilities":[
      {
         "cvss":"9.8",
         "code":"234234",
         "title":"scary vuln"
      },
      {
         "cvss":"7.8",
         "code":"222222",
         "title":"somewhat scary vuln"
      }
   ]
}

 

 

 Working sample in Power Automate Desktop

iterate_json_custom_object.png

 

 

shoebsayyed
New Member

For a json file of the following structure : 

shoebsayyed_0-1652452880658.png

I did the following : 

shoebsayyed_1-1652452928156.png

I have read FileContents as a SingleTextValue

In the RPA flow above, please do not add the part where I am creating a new list. It's not needed

In the display message I printed the json object with property: PONumber as follows : 

shoebsayyed_2-1652452986024.png

it printed the PONumber as follows : 

shoebsayyed_3-1652453081425.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.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

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.

Super User 2 - 2022 Congratulations 768x460.png

Welcome Super Users

The Super User program for 2022- Season 2 has kicked off!

Top Solution Authors
Top Kudoed Authors
Users online (3,410)