Search code examples
pythonjsonjsonparser

how do I compare 2 json files and fetch the difference of only 2 key/value pairs and print them using python


I have 2 similar json files like below with the same keys. I need to find the difference of only one key in both the files (id_number) and store the name if there is a difference. Is there any way to do that?

[
 {
   "id_number": "SA4784",
   "name": "Mark",
   "birthdate": None
 },
 {
   "id_number": "V410Z8",
   "name": "Vincent",
   "birthdate": "15/02/1989"
 },
 {
   "id_number": "CZ1094",
   "name": "Paul",
   "birthdate": "27/09/1994"
 }
]

Solution

  • Load the two files into dicts, step through them with a loop and on each iteration compare the id_number of each. If they're different, output the name field.