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 / Parse JSON into append...
Power Automate
Answered

Parse JSON into appended records

(0) ShareShare
ReportReport
Posted on by 4

Hey guys, 

 

I am struggling to create records from nested JSON in Power Automate. I've been racking my head on this for days and I'm stuck. Essentially what I am trying to do is:

  1. Call an API and receive a data response
  2. Transform the data response into records that can be stored in a database
  3. Write the records to my database

The part I am stuck with is transforming the JSON data response into records, number 2 from above list. Below is my flow at this point, which runs in a loop, receiving multiple pages of JSON.

flow.PNG

 

Here is a sample of the data that is returned on one single page from my responses:

 

{
 "paging": {
 "start": 0,
 "count": 10,
 "links": [],
 "total": 8
 },
 "elements": [
 {
 "latestDataAt": 1716188340000,
 "learnerDetails": {
 "name": "John Doe",
 "enterpriseGroups": [],
 "entity": {
 "profileUrn": ""
 },
 "email": "jdoe@server.com",
 "customAttributes": {},
 "uniqueUserId": ""
 },
 "activities": [
 {
 "engagementType": "SECONDS_VIEWED",
 "lastEngagedAt": 1712606340000,
 "firstEngagedAt": 1709653828535,
 "assetType": "COURSE",
 "engagementMetricQualifier": "TOTAL",
 "engagementValue": 1533
 },
 {
 "engagementType": "PROGRESS_PERCENTAGE",
 "lastEngagedAt": 1712606340000,
 "firstEngagedAt": 1709653828535,
 "assetType": "COURSE",
 "engagementMetricQualifier": "TOTAL",
 "engagementValue": 65
 }
 ],
 "contentDetails": {
 "contentProviderName": "LinkedIn",
 "name": "Agile Software Development",
 "contentUrn": "urn:li:lyndaCourse",
 "locale": {
 "country": "US",
 "language": "en"
 }
 }
 },
 {
 "latestDataAt": 1716188340000,
 "learnerDetails": {
 "name": "Bob Smith",
 "enterpriseGroups": [],
 "entity": {
 "profileUrn": ""
 },
 "email": "bsmith@server.com",
 "customAttributes": {},
 "uniqueUserId": ""
 },
 "activities": [
 {
 "engagementType": "SECONDS_VIEWED",
 "lastEngagedAt": 1712604660000,
 "firstEngagedAt": 1712079072779,
 "assetType": "COURSE",
 "engagementMetricQualifier": "TOTAL",
 "engagementValue": 653
 },
 {
 "engagementType": "PROGRESS_PERCENTAGE",
 "lastEngagedAt": 1712604660000,
 "firstEngagedAt": 1712079072779,
 "assetType": "COURSE",
 "engagementMetricQualifier": "TOTAL",
 "engagementValue": 100
 },
 {
 "engagementType": "COMPLETIONS",
 "lastEngagedAt": 1712604628084,
 "firstEngagedAt": 1712079072779,
 "assetType": "COURSE",
 "engagementMetricQualifier": "TOTAL",
 "engagementValue": 1
 }
 ],
 "contentDetails": {
 "contentProviderName": "LinkedIn",
 "name": "Software Testing: Tools",
 "contentUrn": "urn:li:lyndaCourse",
 "locale": {
 "country": "US",
 "language": "en"
 }
 }
 }
 ]
}

 

 

The data I am trying to extract is in the "elements" array. My thought was - for each response (page) received, parse the JSON and build records. Append those records to an array variable, and when all pages have returned, run a "For Each" loop to write each record to my storage location. Below is an example of the kind of data I am looking to extract.

datenameemailtypeprogress_percentagecontentprovidercontentname
1716188340000John Doejdoe@server.comcourse65LinkedInAgile Software Development
1716188340000Bob Smithbsmith@server.comcourse100LinkedInSoftware Testing Tools

 

Any assistance you can provide to point me in the right direction would be greatly appreciated. I am starting to feel a little exhausted with this one as I have made a full circle trying different things over the last week. 

 

I think my biggest issue here is I don't know how to parse nested JSON, create records, and append them together. But I may be off on my approach too. 

 

Thanks in advance. 

Categories:
I have the same question (0)
  • DJ_Jamba Profile Picture
    2,837 Super User 2025 Season 2 on at

    Hi @chrisshreves 

    Here's one way:

    Initialise an array variable

    DJ_Jamba_0-1716306257610.png


    Add an action after that, select the My Clipboard tab and paste the code below into that tab.

    {"id":"e90ac495-7c31-47cc-9984-863e4fd72c11","brandColor":"#8C3900","connectionReferences":{"shared_office365users_1":{"connection":{"id":"/providers/Microsoft.PowerApps/apis/shared_office365users/connections/6c6be125e77e44c58b1d249bf0d70399"}},"shared_sharepointonline":{"connection":{"id":"/providers/Microsoft.PowerApps/apis/shared_sharepointonline/connections/0c064ee9258b4ed9b982f1bd1e90fbcc"}}},"connectorDisplayName":"Control","icon":"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHZlcnNpb249IjEuMSIgdmlld0JveD0iMCAwIDMyIDMyIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPg0KIDxwYXRoIGQ9Im0wIDBoMzJ2MzJoLTMyeiIgZmlsbD0iIzhDMzkwMCIvPg0KIDxwYXRoIGQ9Im04IDEwaDE2djEyaC0xNnptMTUgMTF2LTEwaC0xNHYxMHptLTItOHY2aC0xMHYtNnptLTEgNXYtNGgtOHY0eiIgZmlsbD0iI2ZmZiIvPg0KPC9zdmc+DQo=","isTrigger":false,"operationName":"Scope","operationDefinition":{"type":"Scope","actions":{"Example_JSON":{"type":"Compose","inputs":{"paging":{"start":0,"count":10,"links":[],"total":8},"elements":[{"latestDataAt":1716188340000,"learnerDetails":{"name":"John Doe","enterpriseGroups":[],"entity":{"profileUrn":""},"email":"jdoe@server.com","customAttributes":{},"uniqueUserId":""},"activities":[{"engagementType":"SECONDS_VIEWED","lastEngagedAt":1712606340000,"firstEngagedAt":1709653828535,"assetType":"COURSE","engagementMetricQualifier":"TOTAL","engagementValue":1533},{"engagementType":"PROGRESS_PERCENTAGE","lastEngagedAt":1712606340000,"firstEngagedAt":1709653828535,"assetType":"COURSE","engagementMetricQualifier":"TOTAL","engagementValue":65}],"contentDetails":{"contentProviderName":"LinkedIn","name":"Agile Software Development","contentUrn":"urn:li:lyndaCourse","locale":{"country":"US","language":"en"}}},{"latestDataAt":1716188340000,"learnerDetails":{"name":"Bob Smith","enterpriseGroups":[],"entity":{"profileUrn":""},"email":"bsmith@server.com","customAttributes":{},"uniqueUserId":""},"activities":[{"engagementType":"SECONDS_VIEWED","lastEngagedAt":1712604660000,"firstEngagedAt":1712079072779,"assetType":"COURSE","engagementMetricQualifier":"TOTAL","engagementValue":653},{"engagementType":"PROGRESS_PERCENTAGE","lastEngagedAt":1712604660000,"firstEngagedAt":1712079072779,"assetType":"COURSE","engagementMetricQualifier":"TOTAL","engagementValue":100},{"engagementType":"COMPLETIONS","lastEngagedAt":1712604628084,"firstEngagedAt":1712079072779,"assetType":"COURSE","engagementMetricQualifier":"TOTAL","engagementValue":1}],"contentDetails":{"contentProviderName":"LinkedIn","name":"Software Testing: Tools","contentUrn":"urn:li:lyndaCourse","locale":{"country":"US","language":"en"}}}]},"runAfter":{},"metadata":{"operationMetadataId":"1f8b5995-f6f3-432b-8db5-9a7d8ec0f1cc"}},"Parse_JSON":{"type":"ParseJson","inputs":{"content":"@outputs('Example_JSON')","schema":{"type":"object","properties":{"paging":{"type":"object","properties":{"start":{"type":"integer"},"count":{"type":"integer"},"links":{"type":"array"},"total":{"type":"integer"}}},"elements":{"type":"array","items":{"type":"object","properties":{"latestDataAt":{"type":"integer"},"learnerDetails":{"type":"object","properties":{"name":{"type":"string"},"enterpriseGroups":{"type":"array"},"entity":{"type":"object","properties":{"profileUrn":{"type":"string"}}},"email":{"type":"string"},"customAttributes":{"type":"object","properties":{}},"uniqueUserId":{"type":"string"}}},"activities":{"type":"array","items":{"type":"object","properties":{"engagementType":{"type":"string"},"lastEngagedAt":{"type":"integer"},"firstEngagedAt":{"type":"integer"},"assetType":{"type":"string"},"engagementMetricQualifier":{"type":"string"},"engagementValue":{"type":"integer"}},"required":["engagementType","lastEngagedAt","firstEngagedAt","assetType","engagementMetricQualifier","engagementValue"]}},"contentDetails":{"type":"object","properties":{"contentProviderName":{"type":"string"},"name":{"type":"string"},"contentUrn":{"type":"string"},"locale":{"type":"object","properties":{"country":{"type":"string"},"language":{"type":"string"}}}}}},"required":["latestDataAt","learnerDetails","activities","contentDetails"]}}}}},"runAfter":{"Example_JSON":["Succeeded"]},"metadata":{"operationMetadataId":"b4c1db60-7643-421c-a826-3c028f282418"}},"Select_3":{"type":"Select","inputs":{"from":"@body('Parse_JSON')?['elements']","select":{"activities":"@item()?['activities']","name":"@item()?['learnerDetails']?['name']","email":"@item()?['learnerDetails']?['email']","content provider":"@item()?['contentDetails']?['contentProviderName']","content name":"@item()?['contentDetails']?['name']"}},"runAfter":{"Parse_JSON":["Succeeded"]},"metadata":{"operationMetadataId":"0588a5db-5e9a-4b6f-ab24-9db633786356"}},"Apply_to_each":{"type":"Foreach","foreach":"@body('Select_3')","actions":{"Apply_to_each_2":{"type":"Foreach","foreach":"@item()?['activities']","actions":{"Append_to_array_variable":{"type":"AppendToArrayVariable","inputs":{"name":"contentArray","value":{"date":"@items('Apply_to_each_2')?['lastEngagedAt']","name":"@items('Apply_to_each')?['name']","email":"@items('Apply_to_each')?['email']","type":"@items('Apply_to_each_2')?['assetType']","progress_percentage":"@items('Apply_to_each_2')?['engagementValue']","contentprovider":"@items('Apply_to_each')?['content provider']","contentname":"@items('Apply_to_each')?['content name']"}},"runAfter":{},"metadata":{"operationMetadataId":"6f75fd16-2691-4d18-99eb-b8c28609e32a"}}},"runAfter":{},"metadata":{"operationMetadataId":"3e5d61d4-3cbd-4e5e-a914-eca09e231f71"}}},"runAfter":{"Select_3":["Succeeded"]},"metadata":{"operationMetadataId":"7ae1d718-f054-4a95-be8f-e859fccffc90"}},"Compose_2":{"type":"Compose","inputs":"@variables('contentArray')","runAfter":{"Apply_to_each":["Succeeded"]}}},"runAfter":{"Initialise_Content_Array":["Succeeded"]}}}


    Test it out.

    When I ran it, the result of my array was:

    [
     {
     "date": 1712606340000,
     "name": "John Doe",
     "email": "jdoe@server.com",
     "type": "COURSE",
     "progress_percentage": 1533,
     "content_provider": "LinkedIn",
     "contentname": "Agile Software Development"
     },
     {
     "date": 1712606340000,
     "name": "John Doe",
     "email": "jdoe@server.com",
     "type": "COURSE",
     "progress_percentage": 65,
     "content_provider": "LinkedIn",
     "contentname": "Agile Software Development"
     },
     {
     "date": 1712604660000,
     "name": "Bob Smith",
     "email": "bsmith@server.com",
     "type": "COURSE",
     "progress_percentage": 653,
     "content_provider": "LinkedIn",
     "contentname": "Software Testing: Tools"
     },
     {
     "date": 1712604660000,
     "name": "Bob Smith",
     "email": "bsmith@server.com",
     "type": "COURSE",
     "progress_percentage": 100,
     "content_provider": "LinkedIn",
     "contentname": "Software Testing: Tools"
     },
     {
     "date": 1712604628084,
     "name": "Bob Smith",
     "email": "bsmith@server.com",
     "type": "COURSE",
     "progress_percentage": 1,
     "content_provider": "LinkedIn",
     "contentname": "Software Testing: Tools"
     }
    ]

     

     

  • Verified answer
    Chriddle Profile Picture
    8,443 Super User 2025 Season 2 on at

    In pure low code you need filter the activities of each elements for engagementType equals 'PROGRESS_PERCENTAGE' to get the element's engagementValue.

     

    With a little xpath you can get the results much faster with less actions:

    Chriddle_1-1716307992380.png

    Apply to each

    Loops over all responses

     

    Select

    From

    items('Apply_to_each')['elements']

    Map Date

    item()['latestDataAt']

    Map Name

    item()['learnerDetails/name']

    Map Email

    item()['learnerDetails/email']

    Map Type

    first(
    	xpath(
    		xml(json(concat('{"Root":',item(),'}'))),
    		'//activities[engagementType="PROGRESS_PERCENTAGE"]/assetType/text()'
    	)
    )

    Map Progess

    first(
    	xpath(
    		xml(json(concat('{"Root":',item(),'}'))),
    		'//activities[engagementType="PROGRESS_PERCENTAGE"]/engagementValue/text()'
    	)
    )

     Map Provider

    item()['contentDetails/contentProviderName']

     

  • chrisshreves Profile Picture
    4 on at

    @Chriddle 

    Your solution was the ticket! This is exactly what I needed. Full disclosure, it took me about a day to get it integrated. I had to do something slightly different for the 'From' field in the loop, but the xpath is perfect. I didn't know about xpath but it worked. 

     

    To be honest, I need to revisit this to try and understand what you taught me here. I understand we are adding the "Root" element, converting it to XML, then using xpath to naviagate. I'm brand new to xpath, so I don't quite understand it. I also don't understand why you chose to use the 'first' function, but it indeed does exactly what I needed it to do. 

     

    A sincere thank you!

    Chris

  • Chriddle Profile Picture
    8,443 Super User 2025 Season 2 on at

    Maybe some comments will be helpful

     

    The xpath returns an array. Take the first (and only one)
    first(
        xpath(
    Within concat() a JSON string is created from the item with a base element Root (XML must have exactly one root element, item() has multiple)

    json() converts this JSON to an objext which is converted to XML
            xml(json(concat('{"Root":',item(),'}'))),
    From the XML take all activities where engagementType equals "PROGRESS_PERCENTAGE" and from this the assetType (text() selects its text value). This returns an array and there may be multiple matching XML nodes depending on the data.
            '//activities[engagementType="PROGRESS_PERCENTAGE"]/assetType/text()'
        )
    )

     

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 507 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 267 Moderator

#3
abm abm Profile Picture

abm abm 232 Most Valuable Professional

Last 30 days Overall leaderboard