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 / JSON with nested array...
Power Automate
Unanswered

JSON with nested arrays: How to extract the value from a key/value pair WITHOUT using loops

(0) ShareShare
ReportReport
Posted on by 12
Hi y'all,
 
This is a hard one... I am sending an API GET request that returns data for 4000 different records in JSON format. I am attempting to flatten the response, so I can display it in Gallery form in my Power App. However, the JSON structure is incredibly frustrating.
 
I need to extract each value from each key/value pair in both nested arrays "domain_metadata" and domain_private_metadata". For example, my output should have a column called "Department Name": that extracts the value property under the key "Ownership_Department-name".
Two complications that make this even more frustrating:
1) The key/value pairs in these arrays are not consistently on the same index. For some records, the department name key is on index [0]. but for others it might be index[1].
2) The arrays are dynamic. For instance, some records have 2 key/value pairs in the "domain_metadata" array and some have 6.
 
Here is a sample JSON from 2 records that shows the limitations I am talking about:
{
  "body": {
    "results": [
      {
        "resource": {
          "name": "Dataset 1 Title",
          "id": "abcd-efgh",
          "description": "Dataset 1 Description"
        },
        "classification": {
          "domain_category": "Financial",
          "domain_tags": [
            "sampleTag1",
            "sampleTag2",
            "sampleTag3"
          ],
          "domain_metadata": [
            {
              "key": "Ownership_Department-name",
              "value": "Financial Department"
            },
            {
              "key": "Strategic-Area_Strategic-Direction-Outcome",
              "value": "Health and Environment"
            },
            {
              "key": "Publishing-Information_Update-Frequency",
              "value": "Weekly"
            }
          ],
          "domain_private_metadata": [
            {
              "key": "Ownership_Public-Access-Level",
              "value": "Public"
            },
            {
              "key": "Publishing-Information_Automation-Method",
              "value": "Microsoft O365"
            },
            {
              "key": "Publishing-Information_Automation-Method-(if-Other)",
              "value": ""
            }
          ]
        }
      },
      {
        "resource": {
          "name": "Dataset 2 Title",
          "id": "abcd-efgh",
          "description": "Dataset 2 Description"
        },
        "classification": {
          "domain_category": "Geographic",
          "domain_tags": [
            "sampleTag1",
            "sampleTag2"
          ],
          "domain_metadata": [
            {
              "key": "Strategic-Area_Strategic-Direction-Outcome",
              "value": "Locations and Maps"
            },
            {
              "key": "Ownership_Department-name",
              "value": "GIS Department"
            }
          ],
          "domain_private_metadata": [
            {
              "key": "Publishing-Information_Automation-Method",
              "value": "Microsoft O365"
            },
            {
              "key": "Publishing-Information_Automation-Method-(if-Other)",
              "value": ""
            },
            {
              "key": "Ownership_Public-Access-Level",
              "value": "Public"
            }
          ]
        }
      }
    ]
  }
}
 
How can I get all this information flattened so I can work with it? I can't use loops because it has to loop through 4000+ rows and takes too much time. I have a Premium license, so I am open to Premium solutions.
 
Categories:
I have the same question (0)
  • Verified answer
    Chriddle Profile Picture
    8,436 Super User 2025 Season 2 on at
    Fast and easy if you use xpath:
    Compose
    Your JSON
     
    Select
    From:
    outputs('Compose').body.results
    Map Department Name:
    xpath(
    	xml(json(concat('{"Root":{"Item":',item(),'}}'))),
    	'string(//domain_metadata[key = "Ownership_Department-name"]/value)'
    )
  • CU09121927-0 Profile Picture
    12 on at
    @Chriddle Thank you for the fast response! I implemented what you said, and added a check to see if the domain_metadata array contains the key at all. If not, it just returns a null value.

    if(contains(string(item()?['classification']), 'Ownership_Department-name'), xpath(xml(json(concat('{\"Root\":{\"Item\":',item(),'}}'))), 'string(//domain_metadata[key = \"Ownership_Department-name\"]/value)'), null)​​​​​​​

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

#2
Tomac Profile Picture

Tomac 405 Moderator

#3
abm abm Profile Picture

abm abm 252 Most Valuable Professional

Last 30 days Overall leaderboard