← How-To Guides How-To How to pretty-print JSON Use json.dumps(obj, indent=2). Use json.dump(..., indent=2) when writing to a file. dumps indent indent adds newlines and spaces. import json s = json.dumps({'a': 1, 'b': 2}, indent=2)