python pretty print json command line code example
Example 1: python print pretty json
import json
json_data = '[{"ID":10,"Name":"Pankaj","Role":"CEO"},' \
'{"ID":20,"Name":"David Lee","Role":"Editor"}]'
json_object = json.loads(json_data)
json_formatted_str = json.dumps(json_object, indent=2)
print(json_formatted_str)
Example 2: python pretty print json command line
# in command line (given python installed)
python -m json.tool my_json.json
Example 3: python json.dumps pretty print
json.dumps(x, indent=4)