Python JSON

How do you pretty-print JSON in Python with indentation?

Pretty-print JSON in Python using json.dumps() with the indent parameter: json.dumps(data, indent=4) adds 4-space indentation. For 2-space indentation, use indent=2. Add sort_keys=True to alphabetically sort keys: json.dumps(data, indent=4, sort_keys=True). When writing to files, use json.dump() with the same parameters: json.dump(data, f, indent=4). For even prettier output, combine with ensure_ascii=False to preserve Unicode characters: json.dumps(data, indent=4, ensure_ascii=False). The pprint module can also display JSON nicely: pprint.pprint(json.loads(json_string)). For quick visualization without code, paste your JSON into our JSON Beautifier at jsonconsole.com/json-beautifier which formats it instantly. Pretty-printing is essential for debugging, logging, and making JSON human-readable during development. The formatted output helps identify structure issues and improves code reviews.
Last updated: December 23, 2025

Still have questions?

Can't find the answer you're looking for? Please reach out to our support team.