xxxxxxxxxx
import json
data = {"name": "John", "age": 30, "city": "New York"}
print(json.dumps(data, indent=4))
xxxxxxxxxx
import pprint
a = {'c': 2, 'b': 3, 'y': 5, 'x': 10}
pp = pprint.PrettyPrinter(sort_dicts=True)
pp.pprint(a)
# Output:
# {'b': 3, 'c': 2, 'x': 10, 'y': 5}
xxxxxxxxxx
import pprint
# Example dictionary to pretty print
my_dict = {
'key1': 'value1',
'key2': 'value2',
'key3': {
'subkey1': 'subvalue1',
'subkey2': 'subvalue2'
}
}
# Pretty print the dictionary
pprint.pprint(my_dict)