JSON Formatter & Validator
Pretty-print or minify JSON and catch syntax errors. Parsing uses the browser’s own JSON engine, so the text never leaves the page.
—
What this tool does
Format turns compact or messy JSON into indented, readable text. Minify removes every insignificant whitespace character to produce the smallest single-line form. Both operations parse the input first, so invalid JSON is reported with the error message from the parser rather than silently reformatted. Validation, formatting and minification share the same grammar, so a document that formats successfully is a document that parses.
Method
The tool calls JSON.parse to validate and convert the text into values, then
JSON.stringify with either two-space indentation or no extra whitespace to produce the
result. The grammar is the one defined by RFC 8259 (The JavaScript Object Notation
Data Interchange Format) and ECMA-404. One caveat: JSON numbers become JavaScript
double-precision floats, so integers outside the safe integer range (2^53 − 1) can lose precision.
Treat very large identifiers as strings when exactness matters.
Example
| Input (minified) | Output (formatted) |
|---|---|
{"name":"Ada","langs":["en","fr"],"n":3} | {
"name": "Ada",
"langs": [
"en",
"fr"
],
"n": 3
} |
[1, 2, 3] | [
1,
2,
3
] |
Why formatting is a correctness tool, not just a cosmetic one
Minified JSON is valid and unreadable, which makes it easy to ship a mistake. Formatting does not
change the data — the output parses to the same value — but it makes structure visible: a nested
object that should have been an array, a key that is duplicated, a value that is a string where a
number was intended. Most JSON bugs are visible the moment the text is indented.
What "valid" means, precisely
JSON is stricter than JavaScript object notation, and several things that look fine are invalid:
Input Valid JSON? Why {"a": 1,}No Trailing commas are not allowed {'a': 1}No Keys and strings must use double quotes {"a": NaN}No NaN and Infinity are not JSON values {"a": undefined}No undefined does not exist in JSON {"a": 1} {"b": 2}No One document, one value {"a": "line\nbreak"}Yes Escaped control characters are fine
When the formatter reports an error, it is the parser's error and it points at the first character
that could not be understood. That position is usually a few characters before the actual mistake —
a missing comma is noticed when the next key starts, not where it should have been.
What formatting loses
Formatting a document and writing it back can change things that are not semantically part of the
data:
- Key order — a JSON object is unordered by specification. Formatters usually
preserve insertion order, but nothing guarantees it, and comparing two formatted files as text is
therefore unreliable.
- Number representation —
1.0 may come back as 1, and a
large integer may lose precision if the implementation parsed it as a float. - Duplicate keys —
{"a": 1, "a": 2} parses to one value in every
implementation, but which one wins is implementation-defined. The formatter will show one of them. - Whitespace inside strings — preserved, because it is data. Only whitespace
between tokens is normalised.
- Comments — JSON has none. A file with comments (JSONC, JSON5) is not valid JSON
and will be rejected.
Pretty-print versus minify
The two operations are inverse in effect, not in bytes. Pretty-printing adds indentation and newlines
for readability; minifying removes all inter-token whitespace for size. Both preserve the parsed
value. Minifying a 1 MB JSON document typically saves 10–20%, which matters for a payload on the wire
and much less for a file on disk after compression — gzip already removes repeated whitespace very
effectively.
Depth and very large documents
Deeply nested JSON (thousands of levels) can exceed a parser's recursion limit and fail with a stack
error rather than a syntax error. Very large documents are bounded by memory: the whole value is
parsed at once, which is fine for a configuration file and less so for a multi-hundred-megabyte
export. For those, a streaming parser is the right tool, and formatting is usually not what you want
anyway.
What this tool does not do
No schema validation, no JSONPath queries, no conversion to another format. It parses, formats or
minifies, and reports the first syntax error. Validation against a schema is a separate step, and it
answers a different question: not “is this well-formed” but “does it have the fields and types the
application expects”.
Frequently asked questions
Does it sort or reorder keys?
No. It preserves the order in which keys appear, because that order is part of what you pasted and may be deliberate. Sorting is a separate operation with its own trade-off: it makes diffs stable but changes the document. If you need canonical output for hashing or comparison, sort the keys in your own code before serialising.
Can it handle JSON Lines or multiple documents?
Not on this page. It formats one JSON value; a file with one object per line (JSON Lines/NDJSON) is a stream of documents, not a single array, and parsing it as one value fails. Wrap the lines in an array with commas between them, or format each line separately. The error message points at the line where the second document begins.
Why does it reject comments and trailing commas?
Because they are not JSON. RFC 8259 allows neither; the relaxed variants are called JSONC (comments) and JSON5 (comments, trailing commas, other extensions), and a strict parser must reject them. A config file may accept JSONC while an API does not, so the safe interchange format stays the strict one.
What does a JSON formatter do?
It parses your text with the JSON grammar and re-serialises it with indentation, so nested objects and arrays become readable. It also reports the position where invalid JSON fails, instead of returning a partial result.
Does it accept trailing commas or comments?
No. Standard JSON does not allow trailing commas, comments, single-quoted strings or unquoted keys. Those belong to JSON5 or JavaScript object literals, and this tool follows RFC 8259 strictly, as does JSON.parse.
Is my JSON uploaded?
No. Parsing and re-serialisation run entirely in the browser through JSON.parse and JSON.stringify. Nothing is sent to a server.
Why can large integers change value?
JSON numbers are parsed into JavaScript double-precision floats. Integers beyond Number.MAX_SAFE_INTEGER (2^53 − 1) lose precision, so an identifier like 12345678901234567890 may not survive the round trip.
What is the difference between formatting and minifying?
Formatting keeps the same data and adds indentation and newlines for reading. Minifying removes all insignificant whitespace to produce the smallest single-line text. Both are lossless for valid JSON, apart from the number caveat.
Can it reorder or validate keys?
It preserves the order in which keys appear and does not enforce a schema. It reports whether the document is syntactically valid JSON; it does not check that required fields exist or have the right types.
Go deeper
Longer explanations of the problems this tool solves:
Sources
- RFC 8259, The JavaScript Object Notation (JSON) Data Interchange Format.
- ECMA-404, The JSON Data Interchange Syntax.
Everything runs in your browser — nothing you type is uploaded.