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

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Combining JSON duplica...
Power Automate
Unanswered

Combining JSON duplicates to one appending

(0) ShareShare
ReportReport
Posted on by

hi everyone,
I have in my power automate flow below output as JSON. I am trying to combine data where the ID is the same and appending each FileName.
Can please anyone advise how to do this?

[
{
"ID": 87547,
"FileName": "test1.pdf"
},
{
"ID": 87547,
"FileName": "test2.pdf"
},
{
"ID": 87547,
"FileName": "test3.pdf"
},
{
"ID": 87549,
"FileName": "test877.xlsx"
}

]

So Desired output would be:

[
{
"ID": 87547,
"FileName": ["test1.pdf", "test2.pdf", "test3.pdf"]
},
{
"ID": 87549,
"FileName": "test877.xlsx"
}

]



Categories:
I have the same question (0)
  • Verified answer
    Paulie78 Profile Picture
    8,422 Moderator on at
    Re: Combining JSON duplicates to one appending

    Hey @123213123,

     

    I made you a video response to show you how to do it. Check it out and see if it is helpful to you.

     

    https://www.youtube.com/watch?v=TMKuL_fjncU

     

    Hope it helps.

     

    Blog: tachytelic.net

    YouTube: https://www.youtube.com/c/PaulieM/videos

    If I answered your question, please accept it as a solution 😘

     

  • Verified answer
    123213123 Profile Picture
    on at
    Re: Combining JSON duplicates to one appending

    hi Pauli78, thank you so much for helping me so fast and even making a video it worked for me!

    i have 1 more question, what if i have a 3rd and 4th column that should be also reflecting in the 'Combined' output which seems to be duplicates?

    [
    {
    "ID": 87547,
    "FileName": "test1.pdf"
    "Title": "task1"
    },
    {
    "ID": 87547,
    "FileName": "test2.pdf"
    "Title": "task1"
    },
    {
    "ID": 87547,
    "FileName": "test3.pdf"
    "Title": "task1"
    },
    {
    "ID": 87549,
    "FileName": "test877.xlsx"
    "Title": "task2"
    }

    ]

     

  • Verified answer
    Paulie78 Profile Picture
    8,422 Moderator on at
    Re: Combining JSON duplicates to one appending

    You could modify the combined step. At https://youtu.be/TMKuL_fjncU?si=13J9FMPQkAb1Jwbt&t=214 of the video you would add another property to the JSON object and use the expression:

     

    first(body('Filter_array'))['Title']

     

    Like this:

    first.png

     

    The the title would also be included in the output.

     

    Blog: tachytelic.net

    YouTube: https://www.youtube.com/c/PaulieM/videos

    If I answered your question, please accept it as a solution 😘

  • 123213123 Profile Picture
    on at
    Re: Combining JSON duplicates to one appending

    I'm incredibly grateful for your help – you've been a lifesaver!

  • grantjenkins Profile Picture
    11,063 Moderator on at
    Re: Combining JSON duplicates to one appending

    @123213123 I saw that @Paulie78 provided a great solution already - and definitely what you should use. I just wanted to show an alternative way of achieving this using XML and XPath to extract out the data 🙂.

     

    Note: If you had thousands of items in your original data then this might be a better approach as it avoids the need for an Apply to each so would be much quicker. Otherwise, I'd definitely recommend going with the original solution.

     

    See full flow below. I'll go into each of the actions.

    grantjenkins_0-1702087994965.png

     

    JSON is a Compose that contains your original data.

    grantjenkins_1-1702088021936.png

     

    Select IDs is the same as what Paulie did where it extracts out a simple list of all the IDs. It uses the following expression.

    item()?['ID']

    grantjenkins_2-1702088129159.png

     

    XML is a Compose that converts your JSON data to XML so we can use XPath expressions to extract the data we want.

    xml(json(concat('{"root": { value:', outputs('JSON'), '}}')))

    grantjenkins_3-1702088191407.png

     

    The XML it creates is below.

    <root>
     <value>
     <ID>87547</ID>
     <FileName>test1.pdf</FileName>
     <Title>task1</Title>
     </value>
     <value>
     <ID>87547</ID>
     <FileName>test2.pdf</FileName>
     <Title>task1</Title>
     </value>
     <value>
     <ID>87547</ID>
     <FileName>test3.pdf</FileName>
     <Title>task1</Title>
     </value>
     <value>
     <ID>87549</ID>
     <FileName>test877.xlsx</FileName>
     <Title>task2</Title>
     </value>
    </root>

     

    Select uses the following expressions to build up your final output.

    //From (Unique IDs)
    union(body('Select_IDs'), body('Select_IDs'))
    
    //Map...
    
    //ID
    item()
    
    //Filenames
    xpath(xml(outputs('XML')), concat('//root/value[ID="', item(), '"]/FileName/text()'))
    
    //Title
    first(xpath(xml(outputs('XML')), concat('//root/value[ID="', item(), '"]/Title/text()')))

    grantjenkins_6-1702088973290.png

     

    And the final output would be:

    [
     {
     "ID": 87547,
     "Filenames": [
     "test1.pdf",
     "test2.pdf",
     "test3.pdf"
     ],
     "Title": "task1"
     },
     {
     "ID": 87549,
     "Filenames": [
     "test877.xlsx"
     ],
     "Title": "task2"
     }
    ]

    grantjenkins_5-1702088405477.png

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
Tomac Profile Picture

Tomac 497 Moderator

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 477 Super User 2025 Season 2

#3
chiaraalina Profile Picture

chiaraalina 242

Last 30 days Overall leaderboard