Python Language Calling `json.tool` from the command line to pretty-print JSON output


Example

Given some JSON file "foo.json" like:

{"foo": {"bar": {"baz": 1}}}

we can call the module directly from the command line (passing the filename as an argument) to pretty-print it:

$ python -m json.tool foo.json
{
    "foo": {
        "bar": {
            "baz": 1
        }
    }
}

The module will also take input from STDOUT, so (in Bash) we equally could do:

$ cat foo.json | python -m json.tool