Skip to main content

Notifications

Power Automate - Using Connectors
Answered

Struggling to parse JSON with page numbers

(0) ShareShare
ReportReport
Posted on by 193

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

 

  • Verified answer
    wiredupjax Profile Picture
    wiredupjax 193 on at
    Re: Struggling to parse JSON with page numbers

    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

     

     

  • Re: Struggling to parse JSON with page numbers

    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

  • wiredupjax Profile Picture
    wiredupjax 193 on at
    Re: Struggling to parse JSON with page numbers

    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

     



     

  • Re: Struggling to parse JSON with page numbers

    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
    wiredupjax 193 on at
    Re: Struggling to parse JSON with page numbers

    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

     

  • v-litu-msft Profile Picture
    v-litu-msft on at
    Re: Struggling to parse JSON with page numbers

    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.

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

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,636

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,942

Leaderboard

Featured topics