Python compares two JSON objects, regardless of the order of the elements in them

Is there any way / class / module in python to compare two json objects and print the changes/differences?

I have tried with "json_tools" which is gives fairly good results, however diff failed in case if there are python lists' with elements in different orders in two json objects.

e.g.

JSON 1:

{
    'Person' : 
        {
            'FName'    : 'John',
            'LName'    : 'Rambo',
            'Sex'      : 'Male'
            'Height'   : '6 ft',
            'Weight'   : '90 KG',
            'Children' :
                [
                    {
                        'FName'  : 'Anna',
                        'LName'  : 'Rambo',
                        'Sex'    : 'Female',
                        'Height' : '5 ft',
                        'Weight' : '55 KG',
                    },
                    {
                        'FName'  : 'Jemmy',
                        'LName'  : 'Rambo',
                        'Sex'    : 'Male',
                        'Height' : '5 ft',
                        'Weight' : '60 KG',
                    }

                ]
        }
}

JSON 2:

{
    'Person' : 
        {
            'FName'    : 'John',
            'LName'    : 'Rambo',
            'Sex'      : 'Male'
            'Height'   : '6 ft',
            'Weight'   : '90 KG',
            'Children' :
                [
                    {
                        'FName'  : 'Jemmy',
                        'LName'  : 'Rambo',
                        'Sex'    : 'Male',
                        'Height' : '5 ft',
                        'Weight' : '60 KG',
                    },
                    {
                        'FName'  : 'Anna',
                        'LName'  : 'Rambo',
                        'Sex'    : 'Female',
                        'Height' : '5 ft',
                        'Weight' : '55 KG',
                    }
                ]
        }
}

json diff shows the Two jsons are mismatched.. Logically those are identical..

Is there a good way of json matching and comparing in python?

This question and all comments follow the "Attribution Required."

All Answers

Answers Loading...
Leave a Reply
You must be logged in to post a answer.
About the author