Formatters & Code
JSON Formatter
Format, validate and minify JSON in the browser.
Results appear here.
What the result means
Formatting parses the text as JSON and prints it again. Pretty mode indents with two spaces. Minify mode uses an indent of zero, which drops insignificant whitespace and leaves a single line. The parser does not evaluate the text as a program, so a trailing comma, a comment, or a single-quoted string is an error rather than something to repair. On failure the page shows the engine message. If that message already names a character position, you see it, and no line number is invented when the engine did not provide one. Keys stay in the order the parser kept, which is source order, not alphabetical order. Very large integers can change, because they pass through ordinary JavaScript numbers.
Related tools
Questions
Why is trailing comma invalid?
JSON allows a comma only between values, not after the last value in an object or an array. JavaScript source sometimes accepts that extra comma, but the JSON parser does not. Comments and single quotes fail for the same reason, because they are not part of the grammar. Delete the extra comma and run it again.
Does this sort keys?
No. Keys stay in parsed order; they are not sorted. The parser remembers the order in the text, and the printer writes that same order back. Two objects that differ only by key order will still differ after formatting.
Will large numbers stay exact?
Integers that fit in an ordinary number stay exact aside from spacing. A bigger integer can lose low digits because the parser does not keep arbitrary precision. Whitespace outside strings is stripped and then added back only as indentation. Characters inside strings are kept as their values rather than as the original spelling.