Exercise 9: pprint vs json — Possible Solution ==================================================================== import json from pprint import pprint config = { "server": {"host": "localhost", "ports": (8000, 8001)}, "debug": True, "tags": ["a", "b"], "owner": None, } pprint(config, width=40, sort_dicts=False) print(json.dumps(config, indent=2)) print(json.dumps(config, sort_keys=True)) # Differences: the tuple (8000, 8001) becomes a list [8000, 8001]; # True becomes true and None becomes null; strings use double quotes # instead of single quotes. Output: {'server': {'host': 'localhost', 'ports': (8000, 8001)}, 'debug': True, 'tags': ['a', 'b'], 'owner': None} { "server": { "host": "localhost", "ports": [ 8000, 8001 ] }, "debug": true, "tags": [ "a", "b" ], "owner": null } {"debug": true, "owner": null, "server": {"host": "localhost", "ports": [8000, 8001]}, "tags": ["a", "b"]} WHY THIS WORKS AS AN ANSWER ------------------------------ pprint shows the Python objects as Python would write them, including the tuple, True and None, and it picks the layout itself depending on width. json.dumps converts to JSON, which has no tuple, so the tuple becomes a list; JSON spells its constants true, false and null; and strings must use double quotes. Remember that json.dumps returns a string, which is why it sits inside print(), whereas pprint prints for itself. The sort_keys=True line is the quickest way to get a stable, comparable one-line version.