how to compare below 2 json structure in python
John Gordon
gordon at panix.com
Thu Jun 21 15:06:40 EDT 2012
In <dcd42df5-4cfa-423f-82e1-442cc6c756ab at googlegroups.com> hisan <santosh.ssit at gmail.com> writes:
> 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:
>>> import json
>>> json1 = '{"color": "blue", "amount": 10}'
>>> json2 = '{"amount": 10, "color": "blue"}'
>>> python1 = json.loads(json1)
>>> python2 = json.loads(json2)
>>> print python1 == python2
True
>>>
--
John Gordon A is for Amy, who fell down the stairs
gordon at panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
More information about the Python-list
mailing list