JSON formatter and validator
Format, validate, beautify or minify JSON. Errors are pinpointed, and everything stays in your browser.
Runs 100% in your browserHow to format JSON
- Paste your JSON. Paste or type JSON into the input box.
- Choose formatting. Pick an indent size, minify, or sort keys; the output updates live.
- Copy or download. Grab the formatted result with Copy or Download.
What a JSON formatter does — and why it matters
JSON (JavaScript Object Notation) is the lingua franca of web APIs, configuration files and structured
logs. It is built from four simple things: objects ({}), arrays ([]), a handful
of primitive values (strings, numbers, true, false, null) and the
whitespace between them. That whitespace is purely cosmetic — a parser ignores it — which is exactly why
JSON moves between two states. Over the wire and in storage it is usually minified to a single
dense line to save bytes; in a code editor or a debugger you want it pretty-printed across many
indented lines so the structure is obvious. A formatter is the round trip between those two states, plus a
validation pass that tells you whether the document is well-formed in the first place.
Strict JSON vs. the lookalikes (JSON5, JSONC)
This tool validates against RFC 8259, the official JSON standard, using the browser's
own JSON.parse() engine. That matters because a lot of text that looks like JSON is
not actually valid JSON. The standard forbids comments, trailing commas, single-quoted strings, unquoted
object keys, hex or octal numbers, leading + signs, and special values like
NaN or Infinity. Those conveniences belong to extensions such as
JSON5 and JSONC (the "JSON with comments" used by VS Code and
tsconfig.json). By holding the line at strict JSON, the formatter guarantees that anything it
accepts is something your API, your database column or another language's parser will also accept — no
surprises in production because your editor was lenient.
The errors that actually break your JSON
When validation fails, the status line shows the first problem the parser hits. The same handful of mistakes account for the vast majority of "Unexpected token" errors:
- Trailing commas — a comma after the last item in an object or array
(
[1, 2, 3,]). Legal in JavaScript, illegal in JSON. Delete it. - Single quotes — JSON strings and keys must use double quotes.
{'name': 'x'}is invalid; it must be{"name": "x"}. - Unquoted keys —
{name: "x"}is a JavaScript object literal, not JSON. Every key needs double quotes. - Comments —
// like thisor/* this */are not allowed. Strip them, or use a JSONC-aware tool. - Wrong primitives —
undefined,NaN, function calls and dates have no JSON representation. Usenull, a number, or an ISO-8601 string. - Trailing or duplicate content — two objects pasted back to back, or a stray character after the closing brace, ends parsing early.
Because the error reports the position of the first failure, work top to bottom: fix the earliest error, re-run, and the next one (if any) surfaces. A document with no errors pretty-prints immediately.
Indent, minify, sort — what each option is for
Indent (2 spaces, 4 spaces, tab) controls how deeply nested levels are pushed right. Two spaces is the de-facto web default and what most linters expect; tabs suit teams that configure indent width in the editor. Minify strips every non-essential byte to one line — the form you ship in an API response or bundle into a build, where it commonly removes 10–30% of the size before compression even runs. Sort keys recursively alphabetises every object's keys (leaving array order untouched, since order carries meaning in arrays). Sorting gives you a canonical form: two responses that differ only in key order collapse to identical text, which makes diffs clean, config deduplication trivial, and snapshot tests deterministic.
Everything stays in your browser
Formatting, validation and sorting all run locally through the browser's native JSON engine — nothing is
uploaded, logged or sent to a server — so working with configuration that contains secrets, an API
response with customer data, or a token you are debugging means none of it leaves the tab. (As a general
habit, still treat production secrets carefully in any browser-based tool.) It also means there is no
per-request size cap: the only limit is your device's memory, so multi-megabyte
documents work, just more slowly than small ones. When you need to compare two JSON documents rather than
tidy one, hand off to the JSON diff
tool; to reshape JSON into a spreadsheet, use JSON to CSV.
Working with JSON in code? Our guide to
JSON in JavaScript
covers JSON.parse/stringify, pretty-printing and the gotchas behind most parse errors.
Frequently asked questions
- It validates your JSON and pretty-prints it with consistent indentation, or minifies it to a single line. Invalid JSON is reported with a clear message and the position of the error.
- It won't silently guess, but it pinpoints the first syntax error (e.g. a trailing comma or single quotes) so you can fix it. Strict, standards-compliant JSON only.
- Effectively both. It parses your JSON with the browser's native engine and lints it for syntax errors — trailing commas, single quotes, unquoted keys — reporting the first problem it finds. Valid JSON is then pretty-printed, minified or sorted.
- Because the JSON standard (RFC 8259) forbids both. Comments (// or /* */), trailing commas, single-quoted strings and unquoted keys are JSON5/JSONC features, not JSON. The formatter validates strict JSON so that what it accepts is exactly what JSON.parse() and your APIs will accept. Strip those features before pasting, or run them through a JSON5 converter first.
- It recursively reorders every object's keys into alphabetical order, top to bottom, without touching arrays (array order is meaningful in JSON, so it is preserved). This makes two documents that differ only in key order produce identical output — useful for diffing API responses, deduplicating config files, or getting deterministic output for snapshot tests.
- Minify for anything sent over the wire or stored at scale — API payloads, config bundled into a build, data in a database column. Removing whitespace can shave 10–30% off a typical document before gzip. Pretty-print for anything a human reads or edits: source-controlled config, fixtures, debugging a response.
- No. Pretty-printing and minifying only change whitespace; the parsed value is identical. The one transform that reorders anything is "Sort keys", and even that only changes object key order, never values or array order. Numbers are re-serialised by the JSON engine, so 1e3 becomes 1000 and 1.50 becomes 1.5 — the same number, canonical form.
- It runs in your browser, so very large documents (tens of MB) may be slow depending on your device, but there is no server limit and nothing is uploaded.
- Yes. Parsing and formatting use the browser's native JSON engine locally — no network request is ever made with your content. You can format proprietary configs, access tokens or customer data without it leaving the tab.