Skip to main content

Notifications

Power Automate - Building Flows
Unanswered

Filtering Array based on condition from nested array

Like (1) ShareShare
ReportReport
Posted on 3 Oct 2024 04:31:25 by 2
Hi 
 
Need help with filtering this data based on data in nested array 
 
Input 
 
[
  {
    "id": "1727825406546",
    "attachments": [],
    "mentions": [],
    "reactions": []
  },
  {
    "id": "1727741971470",
    "attachments": [
      {
        "id": "announcement-card-720f1fc6f1ce4454ab3fe65fad0b729d",
        "contentType": "application/vnd.microsoft.teams.messaging-announcementBanner",
        "teamsAppId": "announcement-card"
      },
      {
        "id": "cc4d3943-69d2-426b-994f-d3d62dbbc34b",
        "contentType": "reference",
        "name": "CAMDEN_2024_Teams_background_v02 (1).jpg"
      }
    ],
    "mentions": [],
    "reactions": []
  },
  {
    "id": "1727247153493",
	"attachments": [
      {
        "id": "d4b3f882897646a49294dbcd606fd718",
        "contentType": "application/vnd.microsoft.card.adaptive",
		"teamsAppId": "announcement-card"
	  }
  }
 ]
 
 
I would like to filter this array where attachment array is not empty and contentType element contain "Adaptive"
 
 
Result should be 
 
{
    "id": "1727247153493",
	"attachments": [
      {
        "id": "d4b3f882897646a49294dbcd606fd718",
        "contentType": "application/vnd.microsoft.card.adaptive",
		"teamsAppId": "announcement-card"
	  }
  }
 
 
 
 
 
Categories:
  • Amardeep Raj Profile Picture
    Amardeep Raj 18 on 05 Oct 2024 at 07:33:36
    Filtering Array based on condition from nested array
    Hi there,
     
    Here is the answer to your question
     
    2. Filter Parent Array Where any attachment contains adaptive
     
    @{xpath(xml(json(concat('{"body":{"value":', outputs('Compose_Sample_Data') , '}}'))), '/body/value[attachments/contentType[contains(text(), "application/vnd.microsoft.card.adaptive")]]')}



     
     
    3. Initialize variable
     



     
     
     
     
     



     


     
    If I've answered your question or solved your problem, please mark this question as answered. This helps others who have the same question find a solution quickly via the forum search. If you liked my response, please consider giving it a thumbs up. Thanks.
     
  • Chriddle Profile Picture
    Chriddle 7,159 on 05 Oct 2024 at 07:31:29
    Filtering Array based on condition from nested array
    Pls check JSON before posting 
     
     
    From:
    xpath(
    	xml(json(concat('{"Root":{"Item":', outputs('Compose'),'}}'))),
    	'//Item[contains(attachments/contentType, "adaptive")]'
    )
    Map:
    json(item())['Item']
  • AlexEncodian Profile Picture
    AlexEncodian 4,265 on 05 Oct 2024 at 01:29:26
    Filtering Array based on condition from nested array
    Try this:

    Filter 1: length(item()?['attachments']) is greater than 0 to check if attachments array is not empty
     
    Filter 2: contains(item()?['attachments']?['contentType'], 'adaptive')

     

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

November 2024 Newsletter…

November 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #9 Get Recognized…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 144,411

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 64,328

Leaderboard
Loading complete