This page validates JSON and writes it back in a readable or compact form. Paste an object, an array or a single value, choose Format or Minify, pick an indentation and optionally sort keys. If the text is not valid JSON, the result gives a line, a column and a short message instead of a formatted document.
Validation uses a strict parser written for this page. It follows the JSON grammar, so a document that passes here is valid JSON and will parse in a browser or in Node. That also means the rules are strict: no trailing commas, no comments, no unquoted keys and no single-quoted strings.
Validation and formatting
A valid document is rewritten with the chosen indentation: two spaces, four spaces or a tab. Each key and value pair goes on its own line, arrays put each element on a line, and the closing brace or bracket returns to its parent's level. A byte-order mark at the very start is ignored, because files saved by some Windows tools include one.
An invalid document produces a failure with a line and a column, taken from the position the parser stopped at. That is usually enough to find a trailing comma, a missing quote or a stray character. For example, a comma after the last member of a three-line object is reported at line 3, column 1, and a single-quoted key at line 1, column 2. The page does not try to repair the input, because guessing at a broken document is how data gets corrupted.
Formatting changes whitespace and, when you ask for it, key order. It does not change the text of a number or a string: those tokens are copied from your input rather than rebuilt from a parsed value. The next sections explain why that matters.
Minify, sort and indentation
Minify removes all optional whitespace and writes the document on one line. It is useful before embedding JSON in a URL, a header or a config value where line breaks are awkward. The stats show zero characters saved if the input was already compact.
Sort object keys alphabetically reorders the keys of every object, including nested ones. Arrays keep their order, because array order is data rather than naming. Sorting is convenient for comparing two documents by eye, but it changes the output order, which matters if something downstream depends on key order or on the original formatting.
Indentation has no effect in minify mode, where everything is on one line. In format mode, a tab produces a more compact file than four spaces but renders differently in different viewers. Two spaces is the common choice for source files and diffs.
A worked example
A 113-character object with a nested object and an array was formatted with two spaces and no sorting. The output was 162 characters, with 7 keys, 2 objects, 1 array and a nesting depth of 2.
| Input | Action | Result |
|---|---|---|
| 113-character object | Format, 2 spaces | 162 characters, 7 keys, depth 2 |
| Same object | Minify | 113 characters, 0 saved |
| Two large integers, 61 characters | Format, 2 spaces | 70 characters, every digit unchanged |
| Object with a repeat key, 19 characters | Format, 2 spaces | 22 characters, a reported, value 3 kept |
The formatted output put each key on its own line and expanded the array so each string had a line. The nested owner object gained a second level of indentation. Nothing was reordered, and the null contact value stayed null.
The minified run returned the original 113 characters because the sample was already compact. That is the correct result, not a failure, and the stats say 0 saved rather than inventing a reduction.
Numbers and strings keep their exact text
Most JSON tools parse a number into a JavaScript double and write it back from that value. That is where digits go missing: integers above 253 are rounded, 1.0 becomes 1, and 1e3 becomes 1000. This page does not take that step. It reads the number token as text and writes the same characters back.
In testing, 9007199254740993 came back unchanged, and so did a 30-digit integer. 1.0, 1e3, 1E+3, -0 and 0.10 all kept their original spelling. A 64-bit identifier copied from a database therefore still points at the same record after formatting.
Strings behave the same way. The escape sequences you paste are preserved, so a\/b, caf\u00e9 and say \"hi\" keep their form rather than being decoded and re-escaped. The trade-off is that this page checks the syntax of a number but does not evaluate it, so it cannot tell you whether the value fits a JavaScript number. If another program will read the JSON with JSON.parse, keep large identifiers as strings there.
Duplicate keys and the stats
Duplicate keys are found and reported. When a key appears twice in the same object, the last value is kept, which is what JSON.parse does; the earlier value is dropped. The checklist names up to four repeated keys and the warning line repeats the full list, so a silent overwrite becomes visible. That is a detection and a report, not a repair: the output still contains one value per key.
Keys counts unique property names, including nested ones. Objects and arrays count the containers, and depth is the maximum nesting level, with a top-level scalar at 0 and a flat object at 1. The character count is the length of the output string, so it includes indentation and line breaks.
For a structural view rather than a text view, a dedicated JSON viewer with a collapsible tree is easier. For comparing two documents, format both with the same settings and use the code diff checker. This page does not convert JSON to XML, CSV or YAML; keep a separate converter for that job.