JSON · How-To

How to Format a JSON File

How do I format a JSON file?

SHORT ANSWER

Open the file in any JSON formatter and run it. On this site, drop the file or paste its contents, then click Format. Code editors, jq, and Python's json module are the common alternatives.

The quickest way: a web formatter

Open the formatter, drop the JSON file onto the page or paste its contents, pick an indentation, and click Format. The result is ready to copy or download. Because the tool runs in your browser, the file never leaves your machine.

In your code editor

Most editors can format JSON without a plugin. In VS Code, select the content and run Format Document, or use the format-on-save setting. Editors read the file locally, which makes this a natural choice when you are already working on it.

From the command line

For a quick, scriptable format, jq can pretty-print with `jq . file.json`, and Python's standard library can too with `python -m json.tool file.json`. Both read the file locally and write readable output to your terminal.

Formatting many files at once

For a directory of JSON files, loop over the files with jq or a small script and write each formatted result back. This is the right approach for migrations and bulk cleanups, where a manual paste does not scale.

What to watch after formatting

Formatting succeeds only on valid JSON. Trailing commas and comments are invalid in standard JSON and will cause the tool to error. If a file will not format, validate it first, then format the corrected version.

TRY IT LOCALLY

Try it in your browser with our JSON Formatter. No upload, no server.

Open JSON Formatter →

FAQ

How do I format JSON in VS Code?

Open the file, then run Format Document, or enable format-on-save. VS Code formats JSON natively with your configured indentation.

Can I format JSON in Notepad++?

Yes, with a plugin such as JSTool. Without a plugin, Notepad++ has no built-in JSON formatting.

What is a quick command-line way to format JSON?

`jq . file.json` pretty-prints a file, and `python -m json.tool file.json` does the same with Python's standard library.

Does formatting a JSON file change the data?

No. Formatting changes whitespace and line layout only. Keys, values, and order are preserved exactly.