web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / How to merge three obj...
Power Automate
Unanswered

How to merge three object arrays with different attributes

(0) ShareShare
ReportReport
Posted on by

How to merge three object arrays with different attributes:

 

I've got a challenge where I'm looking to combine three separate arrays of objects that share a common ID but have different keys into a single array.

 

I'm performing a data cleansing exercise where some flags on our contact records have gotten out of wack. Some customers have more than one flag that needs correcting and others just a single one. I'd like to avoid including the attributes that aren't relevant to a particular contact.

 

Examples of the arrays I've built up so far:

 

Array 1:

 

[

  {

    "contactid": "00178844-452e-ed11-9db1-00224818a628",

    "prospect": true

  },

  {

    "contactid": "2c036cc5-e0e5-ec11-bb3d-0022481869da",

    "prospect": true

  },

  {

    "contactid": "53904ebf-3dd2-ec11-a7b5-0022481869da",

    "prospect": true

  }

]

 

Array 2:

 

[

  {

    "contactid": "c89610d3-182a-ec11-b6e6-002248156fd0",

    "customer": true

  },

  {

    "contactid": "53904ebf-3dd2-ec11-a7b5-0022481869d",

    "customer": false

  },

  {

    "contactid": "2c036cc5-e0e5-ec11-bb3d-0022481869da",

    "customer": true

  },

  {

    "contactid": "d06d9d74-2540-ec11-8c62-002248159b41",

    "customer": false

  }

]

 

Array 3:

 

[

  {

    "contactid": "c89610d3-182a-ec11-b6e6-002248156fd0",

    "advocate": true

  },

  {

    "contactid": "53904ebf-3dd2-ec11-a7b5-0022481869d",

    "advocate": false

  }

]

 

 

Desired result:

 

[

  {

    "contactid": "00178844-452e-ed11-9db1-00224818a628",

    "prospect": true

  },

  {

    "contactid": "2c036cc5-e0e5-ec11-bb3d-0022481869da",

    "prospect": true,

    "customer": true

  },

  {

    "contactid": "c89610d3-182a-ec11-b6e6-002248156fd0",

    "customer": true,

    "advocate": true

  },

  {

    "contactid": "53904ebf-3dd2-ec11-a7b5-0022481869da",

    "prospect": true,

    "customer": false,

    "advocate": false

  },

  {

    "contactid": "d06d9d74-2540-ec11-8c62-002248159b41",

    "customer": false

  }

]

 

Ideally, I'd like to avoid for each loops where possible.

 

Please share any help or guidance you can!

Categories:
I have the same question (0)
  • v-yueyun-msft Profile Picture
    Microsoft Employee on at

    Hi , @ciarancandy 

    The best way is to get this result like this:

    vyueyunmsft_0-1707376673604.png

    This is my test flow:

    vyueyunmsft_1-1707376691551.png

    Compose1 and Compose 2 and Compose 3 are the data for your three array.

    vyueyunmsft_2-1707376731015.png

    (1)The Compose 4 action:

    union(
    xpath( xml( json(concat('{"root":{"item":',string(outputs('Compose')),'}}')) ) , '/root/item/contactid/text()' ),
    xpath( xml( json(concat('{"root":{"item":',string(outputs('Compose_2')),'}}')) ) , '/root/item/contactid/text()' ),
    xpath( xml( json(concat('{"root":{"item":',string(outputs('Compose_3')),'}}')) ) , '/root/item/contactid/text()' )
    )

     

    (2) The Select action:

    vyueyunmsft_3-1707376857699.png

    if( equals(split( string(outputs('Compose')) , item() )?[1],null),null , split( split( split( string(outputs('Compose')) , item() )?[1] , ':' )?[1] , '}' )?[0] )

     

    if( equals(split( string(outputs('Compose_2')) , item() )?[1],null),null , split( split( split( string(outputs('Compose_2')) , item() )?[1] , ':' )?[1] , '}' )?[0] )

     

    if( equals(split( string(outputs('Compose_3')) , item() )?[1],null),null , split( split( split( string(outputs('Compose_3')) , item() )?[1] , ':' )?[1] , '}' )?[0] )

     

    If this reply can help you , you can click mark this reply as solution (Accept solution) which can help more people, thanks in advance! 

     

    Best Regards,

    Yueyun Zhang

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Vish WR Profile Picture

Vish WR 780

#2
Valantis Profile Picture

Valantis 668

#3
Haque Profile Picture

Haque 601

Last 30 days Overall leaderboard