CalcSnippets Search
Python 3 min read

`python -m json.tool` Is the Fastest Way to Pretty-Print and Validate JSON Without Opening an App

A practical json.tool guide for developers who inspect API payloads, config files, or copied JSON blobs and want a built-in way to format and validate them from the terminal.

Why this command is worth remembering: sometimes the problem is not logic yet. Sometimes the first problem is simply that the JSON in front of you is unreadable or invalid.

What json.tool is good for

Python’s documentation describes json.tool as a simple command-line interface to validate and pretty-print JSON objects. That is exactly why it belongs in a developer’s utility toolkit.

If you have a JSON file:

python3 -m json.tool data.json

You get formatted output if the JSON is valid, or an error if it is not.

That combination of formatting plus validation is what makes the command so useful.

Why this is better than eyeballing

Raw one-line JSON blobs are not fun to debug. If you copied a payload from logs, a webhook event, or an API response, your first job may simply be to make it readable. Once it is readable, you can start asking good questions about keys, structure, and values.

That is why this command matters. It lowers the cost of turning raw JSON into inspectable data.

A practical pipeline form

If the JSON comes from stdin:

cat payload.json | python3 -m json.tool

or:

curl -s https://example.com/api | python3 -m json.tool

Now the terminal becomes a fast formatting station without requiring another app or browser extension.

Why validation matters just as much as formatting

The docs show that invalid JSON produces an error. That is not a side effect. It is one of the most useful parts of the tool.

If a config or payload fails to parse, it is better to learn that immediately than to keep guessing which downstream system is angry and why.

This is especially useful in debugging workflows where malformed JSON may have been introduced by:

  1. manual edits
  2. shell quoting mistakes
  3. templating output
  4. truncated copy-paste payloads

When to use it

Good use cases include:

  1. inspecting copied API responses
  2. validating JSON config files
  3. checking generated output from scripts
  4. pretty-printing payloads before sharing them

It is not a complete query language like jq, but that is fine. Speed and availability are its strengths.

Why built-in matters

Because Python is already present in many development environments. A built-in formatter/validator you can invoke immediately is often more useful than a theoretically richer tool you have not installed in the environment you are currently in.

That is the sort of convenience that actually saves time.

Fast availability matters in debugging. The best first-step tool is often the one you can run right now without changing the environment first.

That is exactly why small built-ins keep surviving in serious workflows.

Speed matters.

Especially for first-pass validation.

If the JSON is malformed, finding out immediately is already progress. You do not need a richer tool before you have solved the first problem.

That is why json.tool keeps earning its place. It does one humble thing very quickly, and that turns out to be enough surprisingly often.

Final recommendation

If you need to make JSON readable or learn quickly whether it is valid, keep python -m json.tool in easy reach. It is a simple built-in command, but it solves a very common first-step debugging problem quickly and honestly.

Sources

Keep reading

Related guides