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 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
    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

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

#2
Tomac Profile Picture

Tomac 324 Moderator

#3
abm abm Profile Picture

abm abm 232 Most Valuable Professional

Last 30 days Overall leaderboard