JSON Formatter & Minifier
Beautify or minify JSON data. Validates syntax automatically.
Input
Output
Result will appear here...JSON formatting, validation and the errors behind them
JSON (JavaScript Object Notation) is defined by RFC 8259 and ECMA-404, and it is smaller than most people assume. There are exactly six kinds of value: objects, arrays, strings, numbers, the literals true and false, and null. Strings must use double quotes. Numbers may not have leading zeros, a hex prefix, or the values NaN and Infinity. Comments do not exist in the grammar. Any value, not only an object or array, may appear at the top level. Almost every "my JSON will not parse" problem is a violation of one of those rules.
What this formatter does
The page parses your text with the browser's native JSON.parse about half a second after you stop typing, then re-serialises it with JSON.stringify: two-space indentation in Format mode, or no whitespace at all in Minify mode. If parsing fails, the output panel shows the parser's own error message, which points at the first character it could not accept, and the formatted view returns as soon as the text parses again. Nothing is uploaded; the text stays in the page.
Because the output is a fresh serialisation rather than a whitespace edit, a few things are normalised on the way through. Knowing them saves confusion when you diff the result against the original:
- Integer-like keys move first. JavaScript orders own properties with keys such as
"2"ahead of other keys, so{"b":1,"2":2,"a":3}comes back as{"2":2,"b":1,"a":3}. Other keys keep their original order. - Large integers lose precision. JavaScript numbers are IEEE 754 doubles, exact only up to 2^53 - 1 (9007199254740991). A 64-bit ID such as
12345678901234567890is re-printed as12345678901234567000. APIs work around this by sending IDs as strings (Twitter'sid_stris the classic example). - Duplicate keys collapse.
JSON.parsekeeps the last occurrence, so{"a":1,"a":2}becomes{"a":2}with no warning. - Number spelling is canonicalised.
1.0prints as1,1E2as100,-0as0, and a literal outside double range such as1e400parses to Infinity and serialises asnull. - Escapes are rewritten.
écomes back as the characteré, and unnecessary escapes like\/are dropped. The meaning is identical.
Errors you will see, and what they mean
| Input problem | Why it fails | Fix |
|---|---|---|
Trailing comma: {"a":1,} | Commas only separate members; a comma before } or ] is illegal. | Delete the last comma. |
Single quotes: {'a':1} | Only double-quoted strings exist in JSON. | Replace with double quotes; this is JavaScript object syntax, not JSON. |
Unquoted keys: {a:1} | Keys are strings and need quotes. | Write {"a":1}. |
Comments: // note or /* */ | The grammar has no comment token. | Remove them, or treat the file as JSONC and strip comments before parsing. |
NaN, Infinity, undefined | Not JSON values. | Use null or a string. |
True, None | Python spellings; JSON is lowercase true and null. | Serialise with json.dumps instead of str(). |
| Several objects one after another | Only one top-level value is allowed. Log files often use NDJSON, one document per line. | Paste a single line, or wrap the lines in [ ] with commas. |
| Error at position 0 with nothing visibly wrong | An invisible byte order mark (U+FEFF) from a Windows editor, or curly "smart quotes" pasted from a document. | Re-save as UTF-8 without BOM; replace curly quotes with straight ones. |
| Raw line break inside a string | Control characters must be escaped inside strings. | Use \n. |
JSON, JSONC, JSON5 and NDJSON
Several near-JSON dialects are common in developer tooling. JSONC (JSON with comments) is what VS Code uses for settings.json, and TypeScript accepts comments and trailing commas in tsconfig.json. JSON5 goes further with single quotes, unquoted keys, hex numbers and multi-line strings. NDJSON, also called JSON Lines, stores one complete JSON document per line and is the usual shape of structured logs and bulk export files. This formatter is strict RFC 8259: it will reject all three, which is useful when you need to know whether a file is portable to a parser that is not as forgiving as your editor.
Command-line equivalents
jq . data.json # pretty-print (jq -c for minify, jq -S to sort keys)
jq empty data.json # validate only; exit code 0 means well-formed
python3 -m json.tool data.json # pretty-print with 4 spaces
python3 -c "import json,sys; print(json.dumps(json.load(sys.stdin), separators=(',',':')))" < data.json
node -e "console.log(JSON.stringify(JSON.parse(require('fs').readFileSync(0,'utf8')),null,2))" < data.json
Get-Content data.json | ConvertFrom-Json | ConvertTo-Json -Depth 100 # PowerShellSafety notes
JSON.parse never executes code, unlike the eval trick from the early 2000s, so parsing untrusted JSON is safe in itself. The risks appear afterwards: naive deep-merge helpers that copy a parsed "__proto__" key into another object can pollute prototypes, and deeply nested or very large documents can exhaust memory in a recursive handler. Validate structure with a schema (JSON Schema, Zod, pydantic) before trusting the shape.
Client-side, with one honest caveat
Parsing runs entirely in your browser and the page has no upload endpoint. Browser extensions that are allowed to read page content can still see what you paste, so avoid pasting live credentials into any web page, including this one. The JSON Diff and YAML to JSON tools work the same way.How to use
- Paste raw, minified or hand-edited JSON into the Input panel. Parsing runs automatically about half a second after you stop typing.
- Choose Format for two-space indentation, or Minify to strip every byte of whitespace.
- If the panel reports Invalid JSON, read the position in the message; the first illegal character is usually a trailing comma, a single quote or a comment.
- Click Copy to place the result on your clipboard, or Clear to start over.
Common use cases
- Beautifying a minified API response copied from the browser Network tab while debugging.
- Checking that a hand-edited config file (package.json, .eslintrc, a Kubernetes manifest converted from YAML) is still valid before committing.
- Minifying a payload that has to fit in an environment variable, a query parameter or a size-limited message.
- Spotting 64-bit IDs that need to be strings before a JavaScript client silently rounds them.
- Normalising two exports to the same indentation before comparing them in the JSON Diff tool.
- Confirming whether a file is strict JSON or a JSONC file that only your editor tolerates.
Frequently asked questions
Is the JSON I paste sent to your servers?
What is the difference between Format and Minify?
Why does my JSON fail to parse when it looks fine?
Does this support JSON5 or JSONC (comments and trailing commas)?
Why did a long number change after formatting?
Why did the order of my keys change?
Does it handle Unicode, emoji and Indian-language text?
Can it sort keys alphabetically?
Advertisement