Pretty print JSON on the command line with Python

I’m often dealing with little bits of JSON, and sometimes it’s helpful to pretty-print them for readability.

Python has a handy tool to make that easy on the command line: json.tool.

E.g.

echo '{"foo": "bar", "thing": { "baz": 42 } }' | python -m json.tool

prints:

{
    "foo": "bar",
    "thing": {
        "baz": 42
    }
}

Tech mentioned