我比较了两个json文件和深度with库。但能算出输出。我的输出-
{'values_changed':{‘
’{‘_value’:{\n“测验”:{\n“体育”:{\n "q1":“在NBA中哪一个是正确的球队名称?”,\n“选项”:\n“纽约公牛”,\n“洛杉矶国王”,\n“金色Staxx000xxxte勇士”,\n“休斯顿火箭”\n,“回答”:“休斯顿火箭”、“数学”:{\n "q1":{\n "questxxx000xxcion":"5 +7= ?",\n“选项”:\n "10“、"11”、\n "12“、”13“、”回答“:"12”、"qx0000xx2":{“问题”:“12-8= ?",N“选项”:\n "1",\n "2",\n "3",\n "4"\n,\n“答案”:"4"\n }‘,'old_value':'{\n’测验‘:{\n“体育”:{\n "q1":{\n“问题”:“在NBA中哪一个是正确的球队名称?”,“选项”:“纽约公牛”、“洛杉矶国王”、“金色斯塔克斯Golden”、“休斯顿火箭”\n、\n“答案”:"Huston Rocket"\n }\n \n“数学”:{\n "q1":{\n "questxxxxxcion":"5 +7= ?",\n“选项”:"10","11","12",\n“13”N“答案”:"12"\n },\n "qxxx2":{\n“问题”:“12-8= ?",\n”选项“:\n "1",\n "2",\n "3",”4“”n“,\n”回答“:"4"\n }‘,'diff':- \n+++ \n@@ -6,7 +6,7 @@\n选项:\n“纽约公牛”,\n“洛杉矶国王”,\n-“金色Staxxxxxte Warriros",\n+”Staxx000xxxte Warriros",\n "Huston火箭“\n,\n”答案“:"Huston火箭”\n@ -14,7 +14,7 @\n },“数学”:{\n "q1":{ \n - "questxxxxxcion":"5 +7= ?",\n+ "questxxx000xxcion":"5 +7= ?",\n“选项”:"10","11",\n@@ -23,7 @@\n,“答案”:“12”,N- "qxxx2":{\n+ "qx0000xx2":{\n“问题”:“12-8= ?",\n”选项“:[\n "1",‘}}
我想要的输出-
values_changed :
{
"quiz": {
"sport": {
"q1": {
"question": "Which one is correct team name in NBA?",
"options": [
"New York Bulls",
"Los Angeles Kings",
"Golden Staxxxxxte Warriros",
"Huston Rocket"
],
"answer": "Huston Rocket"
}
},
"maths": {
"q1": {
"questxxxxxcion": "5 + 7 = ?",
"options": [
"10",
"11",
"12",
"13"
],
"answer": "12"
},
"qxxx2": {
"question": "12 - 8 = ?",
"options": [
"1",
"2",
"3",
"4"
],
"answer": "4"
}
}
}
}
old_value _
{
"quiz": {
"sport": {
"q1": {
"question": "Which one is correct team name in NBA?",
"options": [
"New York Bulls",
"Los Angeles Kings",
"Golden Staxx000xxxte Warriros",
"Huston Rocket"
],
"answer": "Huston Rocket"
}
},
"maths": {
"q1": {
"questxxx000xxcion": "5 + 7 = ?",
"options": [
"10",
"11",
"12",
"13"
],
"answer": "12"
},
"qx0000xx2": {
"question": "12 - 8 = ?",
"options": [
"1",
"2",
"3",
"4"
],
"answer": "4"
}
}
}
}发布于 2020-01-22 06:35:06
你可以试试
import json
from deepdiff import DeepDiff
# assuming t1 and t2 are two json data
ddiff = DeepDiff(t1, t2)
jsoned = ddiff.to_json()
print(json.dumps(jsoned, indent=4))https://stackoverflow.com/questions/59853741
复制相似问题