I would like to compare two json files and prepare a report via python program. I used one of library which was available called jsoncompare
What I have tried:
from jsoncompare import jsoncompare as json_comp
json_comp.long = int
json_comp.unicode = str
json_comp.xrange = range
a = [
{
"Key": "Name",
"Value": "node1"
},
{
"Key": "owner",
"Value": "jhonson"
},
{
"Key": "managed",
"Value": "yes"
}
]
b = [
{
"Key": "Name",
"Value": "node1"
},
{
"Key": "owner",
"Value": "jhonson"
},
{
"Key": "managed",
"Value": "No"
}
]
# Compare respecting each array's order
json_comp.are_same(a, b)
print(json_comp.are_same(a, b)[1])
Output of above:
Reason: Different values
Expected:
"yes"
Actual:
"No"
Reason: Different values (Check order)
Expected:
{
"Key": "managed",
"Value": "yes"
}
Actual:
{
"Key": "managed",
"Value": "No"
}
When both json matches then I am not getting any output, but even if matches, i need to print values and say Yes in Difference(Yes or No) column in report
Expected output in table format possibly html for example :
logic:
1)value for key Name starts with lowercase + value match -- Yes
2)value for key Name starts uppercase but value matches -- No
3)for other keys When value does not match its - No
4)for other keys When value does match (irrespective of case) its - Yes
can some one suggest any better ways to do that, or any reference please.
