I ended up using jsbeautifier:
import jsbeautifier
opts = jsbeautifier.default_options()
opts.indent_size = 2
jsbeautifier.beautify(json.dumps(d), opts)
Output:
{
"a": "blah",
"c": [1, 2, 3],
"b": "foo"
}
More Related Contents:
- Split / Explode a column of dictionaries into separate columns with pandas
- Access a particular field in arbitrarily nested JSON data [duplicate]
- How to return dictionary keys as a list in Python?
- How to get string objects instead of Unicode from JSON?
- Converting dictionary to JSON
- What is the difference between dict.items() and dict.iteritems() in Python2?
- Alternative to dict comprehension prior to Python 2.7
- How to convert an XML string to a dictionary?
- Storing Python dictionaries
- How can I access the nested data in this complex JSON, which includes another JSON document as one of the strings?
- String to Dictionary in Python [duplicate]
- How to dump a dict to a JSON file?
- Convert a python dict to a string and back
- Why do I get an error “‘unicode’ object does not support item deletion” when trying to delete values from a JSON object?
- How to json_normalize a column with NaNs
- python: read json and loop dictionary
- JSON dumps custom formatting
- JSON object must be str, bytes or bytearray, not dict
- How to completely traverse a complex dictionary of unknown depth?
- Why do I get an error “‘str’ object does not support item deletion” when trying to delete values from a JSON object?
- How to add an element to the beginning of an OrderedDict?
- What is the best way to implement nested dictionaries?
- Filter dict to contain only certain keys?
- When is del useful in Python?
- UnicodeDecodeError: ‘utf8’ codec can’t decode byte 0xa5 in position 0: invalid start byte
- How do I write a Python dictionary to a csv file? [duplicate]
- merging several python dictionaries
- How to save a dictionary to a file?
- Python – ‘ascii’ codec can’t decode byte
- How to change json encoding behaviour for serializable python object?