Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Automate - Building Flows
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!

  • v-yueyun-msft Profile Picture
    on at
    Re: How to merge three object arrays with different attributes

    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

Michael Gernaey – Community Spotlight

We are honored to recognize Michael Gernaey as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 566 Super User 2025 Season 1

#2
David_MA Profile Picture

David_MA 516 Super User 2025 Season 1

#3
stampcoin Profile Picture

stampcoin 492