Blogchevron_rightJSON Tools
JSON Tools

How to Auto-Format JSON in VS Code and Online Tools

Auto-formatting JSON on save is one of the most effective habits you can build as a developer. Here is how to set it up in VS Code and when to use an online formatter instead.

April 18, 2026·6 min read

Auto-Formatting JSON in VS Code

VS Code has built-in JSON formatting support powered by its language server. To enable format-on-save for JSON files, open Settings (Ctrl+,), search for "format on save", and enable it. Then set the default formatter for JSON to the built-in formatter or Prettier if you have it installed.

Add these lines to your workspace or user settings.json to configure JSON formatting: set "editor.formatOnSave" to true and "[json]": { "editor.defaultFormatter": "esbenp.prettier-vscode" } if using Prettier. This ensures every JSON file is formatted consistently whenever you save.

Configuring Prettier for JSON

Prettier is the most popular code formatter for JavaScript ecosystems and handles JSON natively. Install it with npm install --save-dev prettier, then create a .prettierrc file in your project root to configure tab width (2 is the default), print width, and whether to use tabs or spaces.

Prettier enforces a consistent JSON format across your entire team whenever it is integrated into a pre-commit hook via lint-staged. Every JSON file committed to the repository will be formatted to the same standard, eliminating whitespace-only diffs in code reviews.

When to Use an Online JSON Formatter

Online formatters are ideal for one-off tasks where you do not have a project context: formatting an API response copied from a browser, checking a JSON snippet sent in a Slack message, or validating JSON from a third-party service. They require no installation or configuration.

Online tools are also useful when you are on a shared or restricted machine where you cannot install software. Paste the JSON, get an instant formatted and validated result, and move on. For recurring tasks within a project, set up editor integration instead.

Using the Terminal for JSON Formatting

For command-line workflows, Python's built-in json.tool module provides instant formatting: python3 -m json.tool input.json formats the file and prints the result. This requires no installation on any system that has Python (which is most systems).

jq is a more powerful option for complex JSON operations. The command echo '{"a":1}' | jq . formats any JSON piped to it. jq also supports filtering, transformation, and key extraction, making it a swiss-army knife for JSON manipulation in shell scripts.

Try JSON Formatter Free Online

No sign-up required. 100% client-side — your data never leaves your browser.

Open JSON Formatterarrow_forward

Frequently Asked Questions

Does VS Code format JSON by default without Prettier?

Yes. VS Code includes a built-in JSON formatter that handles basic indentation and formatting. Prettier provides more configuration options and consistency with other file types.

Will auto-formatting break my JSON data?

No. Formatting only changes whitespace. Your data, keys, values, and structure are preserved exactly. You can verify this by checking the formatted output against the original with a JSON compare tool.

How do I format JSON from the command line on Windows?

Use Python: python -m json.tool input.json. Alternatively, install jq via Chocolatey (choco install jq) or use the online JSON formatter for one-off formatting.

How to Auto-Format JSON in VS Code and Online Tools