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

suggest change

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

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents