Skip to content

Python print JSON pretty | Example code

  • by

Use JSON dump() method with indent parameter to print JSON pretty in Python. You should use the optional argument indent.

print(json.dumps(dict, indent=4))

Python pretty print JSON example

Simple example code Python’s built-in JSON module can handle that for you:

import json

data = '[{"ID":101,"Name":"John","Role":"Member"},' \

res = json.loads(data)

json_str = json.dumps(res, indent=2)



Python pretty print JSON example

Do comment if you have any doubts or suggestions on this Pytho pretty print topic.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Your email address will not be published. Required fields are marked *