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 / Merging Two Arrays of ...
Power Automate
Unanswered

Merging Two Arrays of Objects With Different Properties and Same IDs

(1) ShareShare
ReportReport
Posted on by 45

Hello everyone, 

 

I am new to handling datasets using JSON and expressions, so I will need your help with this case. 

 

I need to join two arrays of objects. 

 

Array 1: 

 

[
    {
        "Article""01",
        "Description""Product Name 1",
        "Target Weight""0.1"
    },
   
    {
        "Article""02",
        "Description""Product Name 2",
        "Target Weight""0.15"
    },
    {
        "Article""03",
        "Description""Product Name 3",
        "Target Weight""0.9"
    }
]
 
Array 2:
[
    {
        "Article""01",
        "Price""5.00"
    },
    {
        "Article""02",
        "Price""15.00"
    },
    {
        "Article""03",
        "Price""3.50"
    }
]
 
Expected Output:
 
[
    {
        "Article""01",
        "Description""Product Name 1",
        "Target Weight""0.1",
        "Price": "5.00"
    },
   
    {
        "Article""02",
        "Description""Product Name 2",
        "Target Weight""0.15",
        "Price": "15.00"
    },
    {
        "Article""03",
        "Description""Product Name 3",
        "Target Weight""0.9",
        "Price": "3.50"
    }
]
 
I saw a video showing how to do with XPath, but I was wondering if it is possible to achieve that without using XPath or XML. 
Categories:
I have the same question (0)
  • Verified answer
    Ed Gonzales Profile Picture
    4,531 Most Valuable Professional on at

    @MatheusAntunes 

    Ok, this one is a little 'involved' - there might be a more elegant way to manage this, but this is what I came up with:

     

    First thing I did was initialize an array variable.  (I also created two compose actions to house the sample data for array01 and array02)

     

    I used Parse JSON on each of those to get into the details a bit easier:

    edgonzales_0-1650340601541.png

    Next, the fun:

    edgonzales_1-1650341061308.png

    Basically, I worked through each row in Array01, and filtered Array02 on the article from Array01 that I was looking at...

    but this produces an array, so I added the 'first()' bit to mitigate that.  Then, for each row, I would append a new line to my array variable including the data from both arrays (essentially building a third array).  This is the final output:

    edgonzales_2-1650341207165.png

    Hopefully, the pictures explain it well enough.  Keep us posted.

    -Ed

     

    If you liked this reply, please give it a thumbs up! If this reply has answered your question or resolved your challenge, please consider marking it as a Solution. This helps other users find it more easily via search.

     

  • MatheusAntunes Profile Picture
    45 on at

    Thank you @edgonzales! Very well explained. 

     

    I still had some trouble setting this up. My array 02, is not in the same order as my array 01.

     

    When applying the filter to match each article number, the flow is creating a nested loop. Based on your screenshot, you only had to use one loop.  Considering my dataset will have about +20k rows, I am concerned about performance. 

     

    What is that body you put for the filter?

  • TimFe Profile Picture
    16 on at

    Hi @MatheusAntunes 

     

    I ran into the same situation as you did. In case you have not figured it out yet:

    You need to place the body of parsearray02 into the filter array.

    This way for each Object in your 01 Array you will filter the second array so that the object or objects which have the same article number as the one selected in your for each loop will be shown. 

    After this you can join them by using addProperty in a compose action before they are appened to the array variable. 

  • TE-04091706-0 Profile Picture
    4 on at

    @TimFe Is there a way you could post a image of what you are suggesting? I am having the same issue but i am bot being able to replicate what you suggested.

  • TimFe Profile Picture
    16 on at

    Hi @Raphael4 sure:

     

    I have the Dev and the Test Array: which I filter and parse. 

    TimFe_0-1663827358902.png

     

    After this I have to loop through the Dev Array in order to filter the Items from the Test Array:

    TimFe_1-1663827622347.png

    So the Output of this Step are all the Objects from Dev which are included in the Test Array.

    After This you can build a new Object and append it into your JSON or use addproperty to append a single item into your array:

     

    TimFe_2-1663827844286.png

     

    {
    "Name": @{items('Apply_to_each_3')['Name']},
    "StatusDev": @{items('Apply_to_each_3')['StatusDev']},
    "LinkDev": @{outputs('LinkToBase')},
    "StatusTest": @{items('Apply_to_each_4')?['StatusTest']},
    "LinkTest": @{outputs('LinkToTarget')}
    }

     

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

#2
Tomac Profile Picture

Tomac 405 Moderator

#3
abm abm Profile Picture

abm abm 252 Most Valuable Professional

Last 30 days Overall leaderboard