how to compare below 2 json structure in python

H

hisan

sample_json1={{
"globalControlId": 72,
"value": 0,
"controlId": 2
},
{
"globalControlId": 77,
"value": 3,
"controlId": 7
}
}

sample_json2={
{
"globalControlId": 77,
"value": 3,
"controlId": 7
},
{
"globalControlId": 72,
"value": 0,
"controlId": 2
}
}
 
J

John Gordon

In said:
sample_json1={{
"globalControlId": 72,
"value": 0,
"controlId": 2
},
{
"globalControlId": 77,
"value": 3,
"controlId": 7
}
}
sample_json2={
{
"globalControlId": 77,
"value": 3,
"controlId": 7
},
{
"globalControlId": 72,
"value": 0,
"controlId": 2
}
}

Assuming you have valid json strings (which these aren't), I think you
could convert them into python objects with json.loads() and then compare
the python objects.

For example:
 
M

MRAB

sample_json1={{
"globalControlId": 72,
"value": 0,
"controlId": 2
},
{
"globalControlId": 77,
"value": 3,
"controlId": 7
}
}

sample_json2={
{
"globalControlId": 77,
"value": 3,
"controlId": 7
},
{
"globalControlId": 72,
"value": 0,
"controlId": 2
}
}
That doesn't look like valid JSON.

The only container types in JSON are list (delimited by "[" and "]")
and dict (delimited by "{" and "}").
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top