JSON Formatter & Validator
Paste JSON, drop a file, and get it beautified, minified, or just validated — entirely in your browser, so API keys and customer data in your payloads never touch a server. When parsing fails, this tool does the part most formatters skip: it pinpoints the line and column, shows the offending line with a caret under the exact character, and suggests the likely fix for the classic mistakes — trailing commas, single quotes, unquoted keys, and stray NaN values.
Privacy: parsing happens 100% in your browser — your JSON never leaves this page.
How to use the json formatter & validator
- Paste your JSON into the box, or drag a .json file onto it (files load locally via FileReader — nothing is uploaded).
- Click Beautify for pretty-printed output with your chosen indent (2 spaces, 4 spaces, or tabs), Minify to strip all whitespace, or Validate only for a pass/fail check.
- If parsing fails, read the error panel: line and column, the offending line with a caret, and hints for the most common syntax mistakes.
- Optionally sort keys alphabetically (great for diffs) or escape non-ASCII characters to \uXXXX form for systems that mangle UTF-8.
- Check the stats bar for size before/after, total key count, and maximum nesting depth, then copy the output.
The 8 most common JSON syntax errors — and the fix
| Mistake | Broken | Fix |
|---|---|---|
| Trailing comma | {"a": 1,} | {"a": 1} |
| Single quotes | {'a': 'x'} | {"a": "x"} |
| Unquoted key | {a: 1} | {"a": 1} |
| NaN / Infinity / undefined | {"v": NaN} | {"v": null} |
| Comments | {"a": 1} // note | Remove (or use JSONC tooling) |
| Unescaped quote in string | {"q": "say "hi""} | {"q": "say \"hi\""} |
| Missing comma | {"a": 1 "b": 2} | {"a": 1, "b": 2} |
| Concatenated documents | {"a":1}{"b":2} | Wrap in an array or split (NDJSON) |
JSON is not a JavaScript object literal
Most invalid JSON is actually valid JavaScript that someone copied out of a code file. JavaScript object literals tolerate unquoted keys, single quotes, trailing commas, comments, and values like undefined and NaN; JSON (RFC 8259) allows none of those. JSON also requires double-quoted keys, permits exactly six value types (object, array, string, number, true/false, null), and bans hex numbers (0xFF) and leading plus signs. The reverse trap exists too: {"__proto__": {}} is perfectly legal JSON but a prototype-pollution hazard if you merge parsed objects naively in JavaScript.
What minification actually saves
Pretty-printing adds indentation and newlines that scale with nesting depth. A typical 100 KB API response pretty-printed at 2-space indent often minifies to roughly 60–75 KB — a 25–40% reduction before compression. After gzip or brotli, the gap narrows sharply (whitespace compresses extremely well), so minify for storage quotas, localStorage limits, and logs, but do not expect large transfer savings on endpoints that already serve compressed responses. The stats bar above shows exact before/after byte counts for your document so you can measure instead of guessing.
Frequently asked questions
Is it safe to paste sensitive JSON (API responses, tokens) here?
Yes — everything runs in your browser with JavaScript's built-in JSON.parse and JSON.stringify. There is no upload, no server-side processing, and no analytics on your input. You can verify by loading the page, disconnecting from the network, and formatting: it works offline.
Why does my JSON fail with “Unexpected token” when it looks fine?
The three usual suspects are invisible: a UTF-8 byte-order mark at the start of a saved file (this tool strips it automatically), smart quotes (“ ”) pasted from a word processor instead of straight quotes, and non-breaking spaces copied from web pages. If the caret in the error panel points at what looks like a normal space or quote, retype that character by hand.
Should I use 2 spaces, 4 spaces, or tabs for JSON indentation?
It is pure convention — JSON.parse ignores all of it. 2 spaces is the dominant choice (npm, Prettier, and most JavaScript tooling default to it) and keeps deeply nested documents readable without horizontal scrolling. Use whatever your repository's formatter enforces; consistency matters more than the number.
What does “sort keys” do, and when is it useful?
It recursively rewrites every object with its keys in alphabetical order. Since JSON objects are officially unordered, this changes nothing semantically — but it makes two documents diff cleanly, which is invaluable for comparing API responses, reviewing config changes in pull requests, and generating stable cache keys or content hashes.
Why escape non-ASCII characters to \uXXXX?
Escaped output ({"city": "D\u00fcsseldorf"}) is pure ASCII, so it survives transports and legacy systems that mishandle UTF-8 — old databases, email pipelines, log processors with wrong charset settings. The data is identical after parsing; only the wire format changes. If your whole pipeline is UTF-8 clean, leave it off — raw UTF-8 is smaller and human-readable.
Can this handle very large JSON files?
Files up to a few megabytes format instantly. Above 5 MB the tool warns you first, because JSON.parse is synchronous and a 50 MB document can freeze the tab for several seconds. For files in the hundreds of megabytes, browser tools are the wrong instrument — use a streaming command-line tool like jq instead.
Related tools
- JSON Escape / UnescapeEscape text for JSON strings or unescape JSON back to plain text — quotes, backslashes, newlines, and unicode handled correctly both ways.
- YAML Validator / LinterValidate YAML in your browser with line-numbered errors — catch indentation mistakes, tabs, and duplicate keys in Kubernetes and CI configs.
- SQL Formatter / BeautifierFormat and beautify SQL queries in your browser — keyword casing, clause indentation, and comma style for MySQL, Postgres, and standard SQL.
- HTML Formatter / BeautifierBeautify messy HTML with proper tag-aware indentation or minify it for production — formatted in your browser with one-click copy.
- JSON ⇄ CSV ConverterConvert JSON to CSV and CSV to JSON in your browser — nested objects flattened to dot-notation columns, delimiter options, and file download.
- Base64 ⇄ Image ConverterConvert Base64 to an image and images to Base64 data URIs in your browser — instant preview, PNG, JPG, WebP and SVG support, nothing uploaded.