JSON Formatter | Beautify
text / json JSON Formatter
Format, validate, and minify JSON in your browser. Paste a document to pretty-print it with the indentation you prefer, collapse it to a single line, sort its keys alphabetically, or generate TypeScript interfaces from it. Syntax errors are reported with a line and column so you can find the stray comma quickly. Nothing is uploaded — API responses and configuration files containing credentials stay on your device.
What JSON actually specifies
JSON is defined twice, compatibly: RFC 8259 and ECMA-404. Both describe syntax only — neither says anything about how numbers are stored.
What the actions do
Beautify
Re-indents the document with two, four, or eight spaces per level. This is the fix for a minified API response that arrived as one unreadable line, or for a configuration file whose indentation has drifted after several hands have edited it.
Minify
Removes every space and newline that is not inside a string. The result is identical data in fewer bytes, which is what you want when embedding JSON in a query parameter, an environment variable, or a request body where size matters.
Sort keys
Orders object keys alphabetically, recursively. Two configuration files that differ only in key order produce a noisy diff; sorting both first reduces it to the real changes. Array order is left alone, because in an array the order is part of the data.
TypeScript interface
Infers TypeScript interfaces from a sample document. Nested objects become separate named interfaces rather than one deeply inlined type, arrays are typed from their contents, and null values become optional properties. Paste a real API response and get a usable starting point instead of typing it out by hand.
Reading the error messages
When parsing fails, the message from the JavaScript engine is shown along with the line and column where it gave up. That position is where the parser noticed the problem, which is not always where the mistake is: a missing closing brace is usually reported at the end of the document, well past the object that was never closed.
The errors that come up most often:
- Trailing commas.
[1, 2, 3,]is valid JavaScript and invalid JSON. This is the single most common cause of a document that "looks fine". - Single quotes.JSON strings require double quotes.
{'a': 1}is a JavaScript object literal, not JSON. - Unquoted keys.Every key must be a quoted string, even a simple one.
- Comments.JSON has none. Formats that appear to allow them — JSON5, JSONC in editor configuration — are extensions, not JSON.
- A stray BOM or smart quote.Text copied from a word processor often carries curly quotes that look almost identical to straight ones and parse as neither.
Common uses
- Reading an API response.Production APIs return minified JSON; pretty-printing it is the fastest way to see the shape of what came back.
- Checking a configuration file.Validate a
package.json, atsconfig.json, or a deployment manifest before committing it. - Preparing a request body.Compose the JSON legibly, then minify it for a curl command or an environment variable.
- Diffing two documents.Sort the keys of both first, so the comparison shows real changes rather than reordered fields.
- Typing an API client.Generate interfaces from a sample response rather than transcribing field names by hand.
Things that trip people up
- Numbers lose precision.JSON has one number type, parsed as a 64-bit float. An integer beyond 253 — a Twitter-style snowflake ID, for instance — will not survive a round trip intact. Such identifiers are usually transmitted as strings for exactly this reason.
- Key order is not guaranteed.The JSON specification defines objects as unordered. Most implementations preserve insertion order in practice, but nothing requires it.
- Duplicate keys are ambiguous.The specification does not say what should happen; most parsers keep the last occurrence and discard the rest silently.
- Beautifying changes bytes, not meaning.Reformatting alters the whitespace, so any signature or checksum computed over the original will no longer match.
Frequently asked questions
Does formatting change my data?
Why is my JSON valid here but rejected by my server?
Can it handle very large documents?
jq is the better choice.Are comments or trailing commas supported?
tsconfig.json, for instance — strip them before validating here.Is my JSON uploaded anywhere?
Standards and references
- RFC 8259 The JavaScript Object Notation (JSON) Data Interchange Format 2017
- ECMA-404 The JSON Data Interchange Syntax 2017
- RFC 7493 The I-JSON Message Format — interoperable number and string constraints 2015