Printing a big API response with print() gives one endless line. pprint.pp is handy while debugging, which spreads it out and keeps the keys in the order they arrived.
from pprint import pp
response = {"status": "ok", "items": [{"id": 1, "tags": ["a", "b"]}] * 3}
pp(response, width=60)
pp(response, depth=1) # {'status': 'ok', 'items': [...]}
It breaks the structure over lines and indents nested levels once things don’t fit within width, 80 characters by default. depth cuts off anything deeper with ..., which is what I want when I’m only trying to see the shape of a response before digging in.
The difference with the older pprint.pprint is sorting. pprint sorts dict keys alphabetically, pp keeps insertion order. For JSON from an API, the original order is usually how the docs show it, which makes the two easier to compare. pp arrived in Python 3.8.
It’s meant for humans. The output is Python syntax, with single quotes and True and None, so you can’t paste it into a JSON tool. When you need valid JSON, json.dumps(data, indent=2) is the right call.
Further reading: pprint.pp