JSON Formatter & Validator
Paste JSON to validate it with a precise line and column report, pretty-print or minify it, sort keys recursively, inspect the structure as a tree and download the result — all without the text leaving this tab.
1. Paste or type your JSON
Validated as you type, and rewritten in place when you format it. The text never leaves the browser.
Waiting for input.
A copy of the lines around the problem, with the position marked. Your text above is left exactly as you typed it.
2. Statistics
The text box is empty.
3. Tree view
Show the parsed structure as a collapsible tree
When the text parses, the structure appears here as nested objects and arrays with their values. Open the sections you care about.
JSON.parse and
JSON.stringify — your data is never uploaded, logged or sent to an API.
How it works
Validation is delegated to JSON.parse, the same strict parser used by every JavaScript
engine, so a document that passes here is accepted by browsers, bundlers and runtime libraries alike.
When the parser throws, this page reads the position out of the error message and turns it into a line
and column in your own text. The message itself varies between engines, so the panel also inspects
what is actually sitting at that position — a closing brace, a single quote, a curly quote, a bare
word such as undefined — and adds a plain-language explanation plus a short excerpt with
the character marked.
The three transformations are straightforward string operations once the value is parsed.
Pretty-print re-serialises with JSON.stringify(value, null, indent) using the
indent you chose — two spaces, four spaces or a tab. Minify re-serialises with no whitespace
at all, which is what you want when pasting JSON into a query parameter, an environment variable or a
compact storage key. Sort keys walks the whole structure — nested objects included, inside
arrays too — and rebuilds every object with its keys in ascending string order, which makes two
structurally identical payloads produce identical text and keeps version-control diffs readable.
The statistics are counted from the parsed value rather than from the text, so they describe the data
instead of the formatting: the number of characters and lines on one side, and the count of top-level
members plus the maximum nesting depth on the other. The tree view is generated on demand from the
same parsed value. It is built entirely with DOM calls and text nodes, one collapsible
<details> element per object or array, and it is capped at a few thousand nodes so
that a multi-megabyte document cannot lock up the tab.
Accuracy, and where this tool stops
Everything here reflects a real parse, so there are no "looks valid" guesses: either
JSON.parse accepted the text or it did not. Within that, four honest limits are worth
knowing.
- Error positions are the engine's best effort. Chrome, Firefox and Safari word their
SyntaxErrormessages differently, and some report only a line and column while others report a character offset. Where the engine gives no position at all, the excerpt falls back to the end of your input and says so rather than inventing a location. The character shown is where parsing stopped, which for a missing comma or an unfinished string can be a token or two past the real mistake. - Formatting is not byte-for-byte preservation. Numbers are re-serialised by
JavaScript, so
1.0becomes1,1e2becomes100, and integers outside the safe range of ±253−1 can lose precision because they are held as IEEE-754 doubles. Leading zeros and other non-standard number spellings are rejected by the parser in the first place. - Duplicate keys are silently collapsed. The specification says member names should be
unique. If a document repeats one,
JSON.parsekeeps the last occurrence and the earlier ones disappear from the output. Nothing warns you, so a duplicate key is worth hunting for by hand in generated payloads. - Sorting keys changes the text, not just the layout. The order of object members is not significant to JSON consumers, but it is significant to anything that hashes or signs the serialised bytes. Sort before you sign, not after, and expect diffs to move.
Do not use this page to paste secrets you would not type into a browser tab. It never transmits anything, but the text still lives in the page, in your clipboard history and possibly in the browser's session restore — as it would in any editor.
How to use it
- Paste and watch the status line. Validation runs about a fifth of a second after you stop typing. A green result describes the shape of the document; a red one opens the error panel with the line, the column, the offending character and the excerpt.
- Fix the first error, then look again. A parser stops at the first problem, so it reports one issue at a time. Repair the marked position, and the next error — if there is one — will be reported in the same way. Trailing commas are the most common cause and the easiest to spot.
- Choose an indent, then pretty-print. Two spaces suit most APIs and codebases, four spaces match older style guides, and tabs let each reader set their own width. Changing the indent re-formats the current text immediately, so you can compare the three options.
- Minify or sort when you need to. Minify removes every optional space and line break. Sort keys rebuilds each object alphabetically, recursively, which is the usual way to make two documents comparable with a plain text diff.
- Inspect, then take the result away. Open the tree view to confirm the shape and drill into a nested value, then use Copy for the clipboard or Download as .json to save the current text as a file. Clear empties the box and the tree in one click.
The Load a sample button drops in a small document with nested objects and an array, which is a quick way to see what the error panel, the statistics and the tree view look like before you paste your own data.
Frequently asked questions
Is my JSON uploaded anywhere?
No. The textarea is read with JavaScript in this tab and parsed with the browser's own JSON.parse. There is no request, no worker on someone else's server and no analytics on the payload, so the page keeps working with the network disconnected. If you are handling credentials or personal data, you can confirm this by switching off Wi-Fi and using the tool again.
The JSON looks correct, so why does the parser reject it?
Almost always because it is JavaScript rather than JSON. Trailing commas before a closing brace or bracket, single-quoted strings, unquoted property names, // or /* */ comments, undefined, NaN and Infinity, and the curly quotes that word processors insert are all invalid in standard JSON. The error panel above names the position and explains what the parser probably tripped over.
Does formatting change my data?
Whitespace-only changes are safe: pretty-printing and minifying move spaces and line breaks between tokens and never touch values. Two operations do change the text in ways you should review. Sorting keys reorders object members alphabetically — the meaning is unchanged, but diffs and signatures will change. And every value is re-serialised by JSON.stringify, so number literals are normalised (1.0 becomes 1, 1e2 becomes 100), and integers beyond ±2^53 can lose precision.
What do the depth statistic and the truncated tree mean?
Nesting depth counts how many levels of objects and arrays are inside one another — the deepest container counts as one, and an object whose values are all primitives has depth 1. Some parsers in other languages cap nesting low, so the number is worth knowing before you ship a payload. The tree view stops after a few thousand nodes to keep the page responsive; the text and the statistics are unaffected by that limit.
Sources & further reading
- RFC 8259 — The JavaScript Object Notation (JSON) Data Interchange Format — The current standard. Section 2 defines the grammar, section 6 the number format and section 4 the rule that object member names must be unique — the authority behind every message this page shows.
- MDN Web Docs — JSON.parse() — Documents the exact function used for validation, including the SyntaxError it throws and the reviver argument that is deliberately unused here.
- Introducing JSON — json.org — The original, very short definition of the format: the diagram of six value types that explains why comments, trailing commas and single quotes are not part of it.