我如何比较 2 个 json 文件并获取仅 2 key/value 对的差异并使用 python 打印它们

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

我有 2 个类似的 json 文件,如下所示,具有相同的密钥。我需要在两个文件 (id_number) 中找出一个键的区别,如果有区别则存储名称。有什么办法吗?

[
 {
   "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"
 }
]

set(x.keys()) ^ set(y.keys())

类似的东西它会消除你不同的钥匙

将两个文件加载到字典中,循环遍历它们,并在每次迭代中比较每个文件的 id_number。如果它们不同,则输出名称字段。