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)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs