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 / How To Filter Array wi...
Power Automate
Answered

How To Filter Array with Null/Empty/Blank Values in Key:Value Pair

(1) ShareShare
ReportReport
Posted on by 15
I have a Select step which is successfully parsing out JSON values out of a larger response. Here's the setup for it in the Code View:
{
  "type": "Select",
  "inputs": {
    "from": "@body('Parse_JSON_from_Collection')",
    "select": {
      "PBIReport1": "@item()['PBIReport1']",
      "PBIReport2": "@item()['PBIReport2']",
      "PBIReport3": "@item()['PBIReport3']",
      "PBIReport4": "@item()['PBIReport4']",
      "PBIReport5": "@item()['PBIReport5']"
    }
  },
  "runAfter": {
    "Get_Emails": [
      "Succeeded"
    ]
  }
}

The output from this step with data that was parsed out earlier is below:
[
    {
        "PBIReport1": "https://app.powerbi.com/groups/workspace_id_1/reports/report_id_1",
        "PBIReport2": "https://app.powerbi.com/groups/workspace_id_2/reports/report_id_2",
        "PBIReport3": "",
        "PBIReport4": "",
        "PBIReport5": ""
    }
]
 
I'd like to filter the array only to where the value is not null/blank/empty so that I can dynamically create a HTML table because there could be anywhere from 1 to 5 items that were submitted in the response. The output I would be looking for would be something like this:
[
    {
        "PBIReport1": "https://app.powerbi.com/groups/workspace_id_1/reports/report_id_1",
        "PBIReport2": "https://app.powerbi.com/groups/workspace_id_2/reports/report_id_2"
    }
]
 
Is this something that is possible within Power Automate? I have reviewed a lot of posts about removing null rows with Filter Array, but I can't seem to find anything about evaluating KVP sets.

Thanks!
Categories:
I have the same question (0)
  • Expiscornovus Profile Picture
    33,195 Most Valuable Professional on at
    Not sure if this is the best approach, but xpath seems to work for this 😁
     
    Below is an example
     
    1. Select Action From, which uses an xpath query with text() is not empty filter.
    xpath(xml(json(concat('{"root": { value:', variables('TestArray'), '}}'))), '//value/*[normalize-space(text()) != ""]')
    2. Map
    base64ToString(item()['$content'])
     
    3. Compose to convert the xml content back to an array
    array(json(xml(concat('<root>', join(body('Select'), ''), '</root>')))['root'])
    4. End result 
     
  • Verified answer
    Chriddle Profile Picture
    8,441 Super User 2025 Season 2 on at
    You can also avoid creating empty properties from the beginning:
    json(
    	concat(
    		'{',
    		if(
    			not(empty(item()?['Report1'])),
    			concat('"Report1":"', item()['Report1'], '",'),
    			''
    		),
    		if(
    			not(empty(item()?['Report2'])),
    			concat('"Report2":"', item()['Report2'], '",'),
    			''
    		),
    		if(
    			not(empty(item()?['Report3'])),
    			concat('"Report3":"', item()['Report3'], '",'),
    			''
    		),
    		'}'
    	)
    )
     

  • swolfe2 Profile Picture
    15 on at
    Thanks for the replies! Both solutions ended up working as originally laid out, but I went with @Chriddle solution for simplicity. Thanks to both of you for taking the time out of your day to help, I really appreciate it!

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

#2
Tomac Profile Picture

Tomac 321 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard