Need a hand on how to compare two technically same json files and output the differences between them.
CodePudding user response:
diff = {}
for k, v in ref.items():
diff[k] = {}
for key, ref_value in v.items():
if key in exact_match_keys:
if ref_value == samp[k][key]:
diff[k][key] = "matched"
else:
diff[k][key] = "Not Matched"
elif key in percent_match_keys:
ref_n, samp_n = float(ref_value), float(samp[k][key])
p_dif = abs(ref_n - samp_n) / ref_n * 100
diff[k][key] = f"%{p_dif} difference"