JSON
How to Format JSON: Readable Output in the Browser, Editor or Terminal
Published 2026-08-15 · 7 min read
TL;DR: Paste minified JSON into the JSON formatter, pick two or four spaces, press Format, and copy the indented result back into your file.
JSON that arrives from an API is almost always minified: one long line, no indentation, and impossible to review. Formatting re-indents the document and puts each key and value on its own line, which turns a wall of text into something you can scan, diff and debug. This guide covers the three places you can do it: an online formatter, a code editor and the command line. The format itself is defined in the JSON specification.
Why does formatted JSON matter?
Readability is the obvious reason, but the practical one is version control. A minified one-line JSON file produces a diff that spans the entire file for any change; a formatted file produces a diff that touches only the lines that actually changed. If your team reviews config changes or API fixtures, formatted JSON is the difference between a two-line review and a two-hundred-line review.
How do you format JSON in a browser?
The fastest route for a one-off document is the JSON formatter. It runs entirely in the browser, so a payload from a production API never leaves your machine.
- Paste the JSON into the input box.
- Choose an indent width. Two spaces is the most common convention; four spaces is the default in several config ecosystems.
- Press Format. The document re-indents and every key-value pair lands on its own line.
- Copy the result and replace the minified version in your file.
The same tool has a minify mode that does the reverse, so if you started from a readable file and need a compact payload, you can go the other way in the same place.
How do you format JSON in an editor?
VS Code formats a JSON file with Shift+Alt+F, or Format Document in the command palette. The editor ships with a JSON language server that understands the format natively. The same command works in most editors with a JSON plugin installed.
If your project already uses Prettier, it formats JSON, JSONC, YAML and Markdown from the same configuration file. Running the formatter on save means minified files never survive a commit. The convention you choose matters less than applying it consistently.
How do you format JSON from the command line?
Two tools cover almost every case. jq formats with the identity filter, which prints the file with two-space indentation and a trailing newline. Python, installed on most systems, does the same with a one-liner:
# jq
jq . file.json
# Python
python3 -m json.tool file.jsonBoth write to standard output, so redirect to write the file in place: jq . file.json > formatted.json. Note that jq is a full JSON processor, not just a formatter; if you only need indentation, the tools above are simpler.
What is the difference between format and minify?
Formatting adds indentation, line breaks and, in some tools, a trailing newline. Minifying removes all of it, producing the smallest valid document. Both produce exactly the same data, because the whitespace was never part of the payload - only its presentation. Pick the formatter when a human will read the file, and minify when it will travel in a request body, a database column or a CDN-delivered config.
What are the common formatting mistakes?
- Trailing commas are valid in JavaScript but invalid in JSON. A comma after the last key-value pair makes the document fail to parse.
- Comments are not allowed in JSON. If your file has
//or/* */, it is JSONC, not JSON, and a strict parser rejects it. - A formatter needs at least one value. Empty input produces empty output, not an error.
Formatting never changes what a document means. If reformatting a file changes its behavior, the file had a subtle syntax problem that the formatter silently repaired.
The JSON validator reports the line and column of the first problem, so if formatting rejects a document, validate it first to see why.
Related Tools
Related Guides
JSON Syntax Guide: The Six Value Types and the Rules That Catch You
A complete walkthrough of JSON syntax: objects, arrays, strings, numbers, booleans and null, plus the edge cases that break real documents.
Common JSON Errors: The Five Mistakes That Break Every Parse
The short list of JSON parse failures - trailing commas, unquoted keys, missing commas, comments and unbalanced braces - with symptom, cause and fix.
JSON vs YAML: Which Format Should You Use, and How Do You Convert?
JSON for data crossing system boundaries, YAML for configuration humans write. Compare syntax, footguns and how to convert between them losslessly.
How to Validate JSON: Find the Exact Line and Column of a Syntax Error
Validate JSON syntax with the online validator, JSON.parse in JavaScript or json.loads in Python, and diagnose the most common parse errors.
Frequently Asked Questions
Does formatting change the JSON?
No. Formatting only changes whitespace. The data is byte-for-byte equivalent to the minified input, which is why you can format and minify back and forth without loss.
Two spaces or four?
Either is valid. Two spaces is the most common default in the JavaScript ecosystem; four spaces appears in Go and some Python conventions. Pick one and apply it consistently.
Why does my formatted JSON fail to parse?
Almost always a trailing comma, an unquoted key, a single-quoted string or a stray comment that the source had. Validate the document to get the exact line and column.
Can I format JSON with nested objects and arrays?
Yes. Formatting is recursive: nested objects and arrays are indented at every depth, which is what makes a deeply nested config readable.