DEV Community

chaitdwivedi
chaitdwivedi

Posted on

Pretty print JSON on command line

Use python to pretty print JSON on command line using json std library module

python -m json.tool
Enter fullscreen mode Exit fullscreen mode

Example:

echo '{"foo": "bar", "baz": [1, 2, 3]}' | python -m json.tool
Enter fullscreen mode Exit fullscreen mode

Output:

{
    "foo": "bar",
    "baz": [
        1,
        2,
        3
    ]
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)