web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Struggling to parse JS...
Power Automate
Unanswered

Struggling to parse JSON with page numbers

(0) ShareShare
ReportReport
Posted on by 195

Dear PA Community,

 

I am struggling to parse JSON that includes page numbers, etc.  The below JSON is for the entities listed in a human capital management system.  I've tried initializing a variable as array and object then "apply to" to no avail.

 

Here is the JSON I receive:

 

 

{
 "nextPageUrl": null,
 "previousPageUrl": null,
 "results": [
 {
 "id": 2784,
 "clientCode": "7898",
 "clientName": "Tobin Performing Arts",
 "links": [
 {
 "href": "https://www.zzzzzz.com/rest/api/clients/2784",
 "rel": "self"
 },
 {
 "href": null,
 "rel": "Detailed"
 },
 {
 "href": "https://www.zzzzzzz.com/rest/api/clients/2784/legals",
 "rel": "LegalCompanies"
 }
 ]
 },
 {
 "id": 11569,
 "clientCode": "Code1",
 "clientName": "Biz Group",
 "links": [
 {
 "href": "https://www.zzzzzzzz.com/rest/api/clients/11569",
 "rel": "self"
 },
 {
 "href": null,
 "rel": "Detailed"
 },
 {
 "href": "https://www.zzzzzzzz.com/rest/api/clients/11569/legals",
 "rel": "LegalCompanies"
 }
 ]
 }
 ],
 "totalItems": 2,
 "totalPages": 1
}

 

 

Here is the flow thus far:


wiredupjax_1-1604450352027.png

 

Categories:
I have the same question (0)
  • v-litu-msft Profile Picture
    on at

    Hi @wiredupjax,

     

    You could use the expression to extract the array of results and append it into the array variable, for example:

    outputs('Compose')?['results']

    Screenshot 2020-11-04 142406.jpg

     

    Best Regards,
    Community Support Team _ Lin Tu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • wiredupjax Profile Picture
    195 on at

    Thank you!

    I was able to successfully compose, initialize and parse the JSON.

     

    However, when I move into "apply to each" it's still complaining it's an object.

     

    wiredupjax_0-1604509045838.png

     

    wiredupjax_1-1604509067534.pngwiredupjax_2-1604509110574.png

     

  • DmitriiKubyshev Profile Picture
    Microsoft Employee on at

    Hi wiredupjax,

    'apply to each' extracts individua elements from the array and it looks like the schema for individual employee has an 'array' root type the same way as a list of employee. For individual employee schema try to use

     

    {
    "type": "object",
    "properties": {...}
    }

     

     

    Meanwhile, you can parse entire response once with "All employee" like that and use its properties further in the designer:

     

    {
    	"type": "object",
    	"properties": {
    		"results": {
    			"type": "array",
    			"items":{
    				"type": "object",
    				"properties": {
    					"id": {
    						"type": "integer"
    					}
    				}
    			}
    		}
    	}
    }

     

     

    Best regards,

    Dmitry

  • wiredupjax Profile Picture
    195 on at

    Thank you Dmitry. I was able to successfully get the individual information with the following updates:

    wiredupjax_2-1604520627743.png

     

    HOWEVER, I'm only getting 50 employees because it's producing pages.  How do I ask for the "next" page in a flow?

    wiredupjax_1-1604520604781.png

     



     

  • DmitriiKubyshev Profile Picture
    Microsoft Employee on at

    wiredupjax,

    For this particular case you would need to iterate through the pages manually using "Do Until" loop and 'nextPageUrl' property. You can initialize 'nextPageUrl' variable with your initial url and update it from the response to get the next page. Here is an example flow:

    image.png

    And here is the json schema that I used for parsing of 'nextPageUrl' and 'results' array with 'id' property:

    {
     "type": "object",
     "properties": {
     "nextPageUrl": {
     "type": "string"
     },
     "results": {
     "type": "array",
     "items": {
     "type": "object",
     "properties": {
     "id": {
     "type": "integer"
     }
     }
     }
     }
     }
    }

    Best regards,

    Dmitry

  • Verified answer
    wiredupjax Profile Picture
    195 on at

    Final Answer - THANK YOU Microsoft @v-litu-msft and @DmitriiKubyshev 

     

    Sharing so we can all learn:
    Scenario: Pull data from 3rd party mgmt system via API using tokens with a multi-page response:

     

    Get the token & request the company names under the account--

    wiredupjax_0-1604615330961.png

    Setup an Array for all of the employees coming in. Why? Data arriving is as an object and you can't (or at least I do not know) how to "Do While" or "Apply to Each" reading an object--

    wiredupjax_1-1604615449688.png

    Read the JSON for how many pages, put in a variable (string) and convert to an integer.  DO UNTIL for every page found on # of page numbers received from initial HTTP request.  Using counter, APPEND for pagination, copy the data into compose for processing and convert the results of compose into the array.  Once in an array, APPLY TO EACH loop to read and, for us, we are writing the data to a SharePoint list.

    wiredupjax_2-1604615769269.png

     

    wiredupjax_3-1604615794835.png

     

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 463 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 427 Moderator

#3
abm abm Profile Picture

abm abm 245 Most Valuable Professional

Last 30 days Overall leaderboard