What this formatter does
Paste JSON and the output pane shows it pretty-printed with consistent indentation, or minified with all insignificant whitespace removed. The document is parsed first, so the output is always valid JSON, and syntax errors are reported with the line, the column and the likely cause rather than a generic failure.
Two details matter for real data. Large integers are preserved. JavaScript numbers lose precision above 253, so a naive JSON.parse/JSON.stringify round trip turns an ID like 9007199254740993 into 9007199254740992. This formatter re-emits the original digits instead. Duplicate keys are flagged. Most parsers silently keep the last value; here you get a warning with the position.
How JSON formatting works
JSON (RFC 8259) treats spaces, tabs and line breaks between tokens as insignificant. {"a":1} and the four-line version of the same object are the same document. A formatter parses the text into a tree and writes it back out with one property or array element per line, indented by nesting depth. Minifying is the reverse: the same tree is written with no whitespace at all, which is what you want on the wire.
{"user":{"id":42,"tags":["a","b"]}}{
"user": {
"id": 42,
"tags": [
"a",
"b"
]
}
}Two spaces is the most common indentation in JavaScript projects and package.json files. Four spaces is common in Python and Java codebases. Tabs are rare but valid. None of these changes the meaning of the document.
Common JSON syntax errors
These are the mistakes this tool sees most often, with the message you will get and the fix.
| Input | Problem | Fix |
|---|---|---|
{"a": 1,} | Trailing comma before } | Remove the comma after the last property. JavaScript allows it; JSON does not. |
{'a': 1} | Single quotes | Use double quotes for keys and strings. |
{a: 1} | Unquoted key | Keys are always strings: {"a": 1}. |
{"a": 1 "b": 2} | Missing comma between properties | Add a comma after 1. |
{"a": undefined} | undefined, NaN and Infinity are not JSON | Use null, a number, or a string. |
{"a": 007} | Leading zero | Write 7, or quote the value if it is an identifier. |
// note | Comments | JSON has no comments. Strip them, or use a JSONC-aware loader for config files. |
"line | Raw line break inside a string | Escape it as \n. |
{"a": 1} {"b": 2} | Two top-level values | Wrap them in an array, or treat the input as newline-delimited JSON. |
The error position points at the first character the parser could not accept. For a missing comma or closing bracket, the real mistake is usually just before that position.
Formatter vs validator
Formatting requires validation: the tool cannot pretty-print a document it cannot parse. If you only want to know whether a document is valid, and why not, the JSON Validator keeps the full list of diagnostics visible and does not replace your text. If you want to explore a large document rather than read it top to bottom, the JSON Viewer renders it as a collapsible tree with search.
Formatting JSON in code
JavaScript
const pretty = JSON.stringify(value, null, 2); // 2-space indent
const minified = JSON.stringify(value); // no whitespace
// Sorted keys: pass a replacer that returns a key-sorted copy of each object
const sorted = JSON.stringify(value, (k, v) =>
v && typeof v === 'object' && !Array.isArray(v)
? Object.fromEntries(Object.keys(v).sort().map((key) => [key, v[key]]))
: v, 2);
Note the precision caveat above: JSON.parse converts every number to a double. If your data carries 64-bit IDs, parse them as strings or use a BigInt-aware parser.
Python
import json
print(json.dumps(data, indent=2, sort_keys=True))
# Minify:
print(json.dumps(data, separators=(",", ":")))
Command line
# jq pretty-prints by default; -c minifies; -S sorts keys
jq . data.json
jq -c . data.json
jq -S . data.json
# Python's stdlib, no extra install
python -m json.tool data.json
Notes on this implementation
- Parsing and formatting run in your browser. The input is never sent to a server. Files opened with Open file are read with the File API, locally.
- String escapes are normalised to the shortest valid form:
\u0041becomesA, and\/becomes/. Non-ASCII characters are kept as-is (UTF-8), not escaped. - Documents nested more than 512 levels deep are rejected.
- Syntax highlighting is switched off above 300 KB to keep large documents responsive; formatting still works.