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 / Comparing 2 JSONs with...
Power Automate
Answered

Comparing 2 JSONs with same keys to get the differences

(1) ShareShare
ReportReport
Posted on by 6
Hello, I need to compare two JSONs with the same keys, check which keys has different values and isolate those keys and their value. I tried to use the Filter Array function, but it keeps returning me the JSON I put in "From". Do you guys have an idea on how to do this? This is the opposite of the case answered here: https://community.powerplatform.com/forums/thread/details/?threadid=2e9b9f69-2963-42c9-a29d-23d70fc00bb4
 
Thank you.
 
JSON1
[
{
"Key1" : "aaa",
"Key2" : "bbb",
"Key3" : "ccc",
"Key4" : "ddd",
"Key5" : "eee",
"Key6" : "fff",
"Key7" : "ggg",
"Key8" : "hhh",
"Key9" : "iii",
"Key10" : "jjj"
}
]
 
JSON2
[
{
"Key1" : "xxx",
"Key2" : "bbb",
"Key3" : "ccc",
"Key4" : "ddd",
"Key5" : "yyy",
"Key6" : "fff",
"Key7" : "ggg",
"Key8" : "hhh",
"Key9" : "zzz",
"Key10" : "jjj"
}
]
 
The result should be:
[
{
"Key1" : "xxx",
"Key5" : "yyy",
"Key9" : "zzz"
}
]
Categories:
I have the same question (0)
  • Suggested answer
    SudeepGhatakNZ Profile Picture
    14,394 Most Valuable Professional on at
    There are two ways to tackle this
     
    Option 1:
     
    You can use the union() function to merge both JSON arrays into one and then loop through this merged array. For each item, you can check if the corresponding value in both arrays is mismatched. While loops are generally discouraged in larger datasets due to performance concerns, this approach works well for small datasets.
     
    Option 2:
    The second option is to use the Premium actions as suggested in this response
  • Suggested answer
    takolota1 Profile Picture
    4,978 Moderator on at
    Is your data really 2 different JSON objects each containing multiple columns you need to check, or is it 2 JSON arrays with a “Key” column in each object in the array?
     
    Initially lets assume your example is just bad & you actually have…
    JSON1
    [
    {
    “Key”:”aaa”
    },
    {
    “Key”:”bbb”
    },
    {
    ”Key”:”ccc”
    }
    ]
     
    JSON2
    [
    {
    “Key”:”aaa”
    },
    {
    “Key”:”eee”
    },
    {
    ”Key”:”ccc”
    }
    ]
     
    If your JSON objects have key value pairs other than just “Key” Use Select actions with the Map input tabbed to a single box input & the input expression item()[‘Key’] to get arrays of just the Key values for each JSON array.
    Then use the intersect( ) expression on your two arrays to get only an array of values that are the same between the two. From there you can then use a Filter array action where the From is a union( ) of the two sets of values & the Filter condition is where the intersect( ) output Does not contain item(). That way it filters to all values not contained in the list of all similar values, in other words the different values.

     
    If it is really like your example data with 2 large JSON objects then you’ll likely need to use the string( ) expression on your JSON objects to stringify them & then use some split( ) expression on “, to get an array of values for each object. From there you can then use the same intersect( ) & union( ) & Filter array pattern to get those that are not the same.
     

    No premium connectors & no loops required.
  • Chriddle Profile Picture
    8,591 Super User 2026 Season 1 on at
    For simplicity I've extracted the objects from the JSON's array in "Compose" and "Compose 2".
    If your JSONs contain arrays with multiple items, you need to surround this with an Apply to each (and, of course, adapt the expressions accordingly).
     
    I assume that you don't know the object's property names in advance and get them with the help of xpath()
    Be aware that xpath's name function encodes characters that are not alowed in XML node names. If you encounter problems there (e.g. with spaces), check the output of the "Select" and handle this with the function replace()
     
    If you know the property names in advance, just remove the "Select" (that gets these names) and put them as an array of strings into the "Filter array"'s From.
     
     
    Result:
     
     
    Select
    From:
    xpath(
    	xml(json(concat('{"Root":{"Item":', outputs('Compose'),'}}'))),
    	'//Item/*'
    )
    Map:
    xpath(
    	item(),
    	'name(/*)'
    )
     
    Filter array
    From:
    body('Select')
    Filter:
    outputs('Compose')?[item()]
    is not equal to
    outputs('Compose_2')?[item()]
     
    Select 2
    From:
    body('Filter_array')
    Map:
    concat(
    	'"', item(), '":',
    	'"', outputs('Compose_2')?[item()], '"'
    )
     
    Compose 3
    json(
    	concat(
    		'{',
    		join(body('Select_2'), ','),
    		'}'
    	)
    )
     
  • Verified answer
    Chriddle Profile Picture
    8,591 Super User 2026 Season 1 on at
    Another approach with intersection()
     
    concat(
        if(
            and(
                equals(intersection(outputs('Compose'), outputs('Compose_2'))?[item()], null),
                not(equals(outputs('Compose_2')?[item()], null))
            ),
            concat(
                '"', item(), '":',
                '"', outputs('Compose_2')[item()], '"'
            ),
            '***foo***'
        )
    )
     
     
    json(
        concat(
            '{',
            replace(
                replace(
                    join(body('Select_3'), ','),
                    '***foo***,',
                    ''
                ),
                '***foo***',
                ''
            ),
            '}'
        )
    )
     
  • CU14102321-0 Profile Picture
    6 on at
    Hello, guys. Thanks for the quick response.
    All solutions worked for me!!
    The Keys are different from each other within the JSON and identical when compared to the other JSON. I numbered the keys to differentiate them. And I actually know all the keys.
     
    Thank you very much.

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!

Leaderboard > Power Automate

#1
Haque Profile Picture

Haque 67

#2
David_MA Profile Picture

David_MA 64 Super User 2026 Season 1

#3
Expiscornovus Profile Picture

Expiscornovus 39 Most Valuable Professional

Last 30 days Overall leaderboard