Crunching json with python

json, parsing, python

Solution

http://docs.python.org/library/json.html

>>> import json
>>> json.dumps(json.loads("""
... {"node0":{
...     "node1":{
...         "attr0":"foo",
...         "attr1":"foo bar",
...         "attr2":"value with        long        spaces"
...     }
... }}
... """))
'{"node0": {"node1": {"attr2": "value with        long        spaces", "attr0": "foo", "attr1": "foo bar"}}}'

Problem

Echoing my other question now need to find a way to crunch json down to one line: e.g. ``` {"node0":{ "node1":{ "attr0":"foo", "attr1":"foo bar", "attr2":"value with long spaces" } }} ``` would like to crunch down to a single line: ``` {"node0":{"node1":{"attr0":"foo","attr1":"foo bar","attr2":"value with long spaces"}}} ``` by removing insignificant white spaces and preserving the ones that are within the value. Is there a library to do this in python? EDIT Thank you both drdaeman and Eli Courtwright for super quick response!

Original source