JSON Formatter & Validator
The JSON Formatter takes any JSON text and pretty-prints it with your choice of 2 or 4-space indentation, or minifies it down to a single compact line. If the input isn't valid JSON, it parses just far enough to tell you exactly where the syntax breaks, rather than a generic error message. Everything runs locally in your browser as you type.
Paste JSON to validate and format it.
How it works
Formatting valid JSON is a two-step process: the text you paste is parsed into an in-memory JavaScript object using the browser's built-in JSON parser, and that object is then serialized back out as text with the indentation you chose — two spaces, four spaces, or none at all for a minified single line. Because the parser doesn't care about the original formatting, this round trip also normalizes inconsistent spacing and mixed tabs into a clean, consistent structure.
When the input isn't valid JSON, the parser throws as soon as it hits a character that can't legally appear at that point in the grammar — an unquoted key, a trailing comma, a missing colon, or a stray character after the JSON value ends, for example. Rather than surfacing that raw error, this tool walks back through the input to translate the parser's reported character position into a line and column number, and highlights that exact spot, so you can jump straight to the problem instead of scanning the whole document for a missing brace.
All of this — parsing, reformatting, minifying and error localization — happens with JavaScript running in your browser tab. Nothing you paste in is sent to a server or stored anywhere; closing or refreshing the tab discards it.
Frequently asked questions
Why does my JSON fail to parse even though it looks correct?
The most common causes are a trailing comma after the last item in an object or array, single quotes instead of double quotes around keys and strings, or an unquoted key — all valid in JavaScript object literals but not in strict JSON.
What's the difference between pretty-printing and minifying JSON?
Pretty-printing adds indentation and line breaks to make nested structure easy to read; minifying strips all unnecessary whitespace to produce the smallest possible payload, which is what you'd send over the wire in production.
Should I use 2-space or 4-space indentation?
Either is valid JSON; it's purely a readability preference. Two spaces is more common in JavaScript-heavy codebases and keeps deeply nested structures narrower, while four spaces can be easier to scan visually.
Does this tool validate against a JSON Schema?
No — it validates that the text is syntactically well-formed JSON, not that it matches a particular schema or shape. Schema validation is a separate concern that needs the schema itself as an input.
Can I format very large JSON files in the browser?
Yes, within reason — parsing and reformatting run locally using your device's memory and CPU, so extremely large files (tens of megabytes) may be slow or hit browser memory limits depending on your device.