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"
}
Related Contents:
- Split / Explode a column of dictionaries into separate columns with pandas
- What is the difference between dict.items() and dict.iteritems() in Python2?
- How to get string objects instead of Unicode from JSON?
- Converting dictionary to JSON
- Access a particular field in arbitrarily nested JSON data [duplicate]
- How to return dictionary keys as a list in Python?
- Alternative to dict comprehension prior to Python 2.7
- How to convert an XML string to a dictionary?
- Storing Python dictionaries
- How to dump a dict to a JSON file?
- 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]
- Convert a python dict to a string and back
- How to json_normalize a column with NaNs
- JSON object must be str, bytes or bytearray, not dict
- How to completely traverse a complex dictionary of unknown depth?
- How to add an element to the beginning of an OrderedDict?
- Access nested dictionary items via a list of keys?
- Create a dictionary with comprehension
- Flatten nested dictionaries, compressing keys
- What is the best way to implement nested dictionaries?
- How to prettyprint a JSON file?
- Can I get JSON to load into an OrderedDict?
- Python JSON serialize a Decimal object
- What exactly do “u” and “r” string prefixes do, and what are raw string literals?
- How to save a dictionary to a file?
- How to handle a broken pipe (SIGPIPE) in python?
- Python dictionary keys. “In” complexity
- Django TemplateDoesNotExist?
- General Unicode/UTF-8 support for csv files in Python 2.6
- How can I get dict from sqlite query?
- raw_input function in Python
- How to use a multiprocessing.Manager()?
- How to print a dictionary line by line in Python?
- Accessing JSON elements
- Is there a difference between using a dict literal and a dict constructor?
- Python Dictionary to CSV
- Accessing value inside nested dictionaries [duplicate]
- Accessing dict_keys element by index in Python3
- How to customise error response in FastAPI?
- How to iterate through a list of dictionaries in Jinja template?
- Sort nested dictionary by value, and remainder by another value, in Python
- Check if key exists and iterate the JSON array using Python
- Make dictionary from list with python [duplicate]
- Why must dictionary keys be immutable?
- Serialising an Enum member to JSON
- Python string to unicode [duplicate]
- Python to JSON Serialization fails on Decimal [duplicate]
- Random Python dictionary key, weighted by values
- “unpacking” a passed dictionary into the function’s name space in Python?