JSON Formatter and Validator
UpdatedHow do you fix invalid JSON? The usual causes are trailing commas, single quotes instead of double quotes, unquoted keys and a missing bracket. Paste your JSON below: the validator shows where parsing failed, and Repair fixes those slips plus code fences and chat text from LLM replies. Parsing happens in your browser, so no data leaves this tab.
What is JSON formatting?
JSON, defined in RFC 8259, is the most common text-based data interchange format on the web. Every REST API response, every package.json, every CloudWatch event, every Slack webhook payload ships JSON over the wire. The format is deliberately small: six structural tokens ({, }, [, ], ,, :), four literals (true, false, null, plus numbers), and double-quoted strings. That minimalism is also the readability problem. Servers serialize JSON with no whitespace to save bytes, and the resulting single-line blob is illegible past about 200 characters.
Formatting, validation, and minification are three distinct operations on the same parse tree. Formatting (also called pretty-printing or beautifying) inserts indentation and newlines so structure becomes scannable. Validation parses the input and reports whether it conforms to RFC 8259. Minification strips every byte of optional whitespace for production transport. Worked example: the minified API response {"id":42,"name":"Ada","active":true,"tags":["admin","beta"],"score":98.6} is one line of 73 bytes. Reformatted with a 2-space indent, the same payload spans 10 lines and 107 bytes, and you can read it at a glance. We round-trip through JSON.parse and JSON.stringify(obj, null, 2), so the output matches the input apart from whitespace, canonical number and escape formatting (1.0 becomes 1), and integer-like keys, which JavaScript always moves to the front.
How JSON parsing works
RFC 8259 is strict by design. There are no trailing commas after the last element, no // or /* */ comments, no single-quoted strings, no unquoted object keys, no hex literals, no NaN or Infinity. Lenient dialects exist for specific niches: JSONC (used by tsconfig.json and VS Code settings.json) permits comments, and JSON5 adds trailing commas, single quotes, and unquoted keys for hand-edited config. Format and Minify stick to the strict spec on purpose, because that is what APIs send and receive, and a lenient parser would hide the bug instead of showing it. Repair is a separate button you press on purpose, and it lists every change it makes.
Four failure modes account for nearly every parse error we have seen: unmatched brackets (an opener with no closer, or vice versa), missing commas between fields, unquoted keys carried over from a JavaScript object literal, and trailing commas left behind by a copy-paste from a comma-separated list. Worked example: paste {"a":1,"b":2,} and current Chrome and Node report Expected double-quoted property name in JSON at position 13 (line 1 column 14) (older engines say Unexpected token }). Position 13 is the closing brace, but the real offender is the comma just before it. Reading backwards from the reported position against the four failure modes usually finds the problem in seconds. RFC 6901 (JSON Pointer) and JSON Schema draft 2020-12 are adjacent specifications layered on top of the same syntax: JSON Pointer addresses a node by path (/tags/0), and JSON Schema validates structure against a contract. We do not validate against a schema here. We validate that the bytes are well-formed RFC 8259, which is a prerequisite for everything else.
How do you fix JSON from an LLM?
Paste the model's reply above and press Repair. It strips ```json fences and chat text around the JSON, removes trailing commas and comments, quotes bare keys, converts single quotes and Python's True, False and None, escapes raw line breaks inside strings, and closes output that was cut off. It lists every change, and Undo brings back your original.
Here is a typical reply that JSON.parse rejects on the very first character:
Here is the user as JSON:
```json
{
name: 'Ada',
"active": True,
"bio": "Line one
Line two",
"tags": ["math", "poetry",],
}
```Repair turns it into this, with two-space indent:
{
"name": "Ada",
"active": true,
"bio": "Line one\nLine two",
"tags": [
"math",
"poetry"
]
}The fixes list for that example has seven lines: the fence and the “Here is the user” line removed, one bare key quoted, one single-quoted string converted, True changed to true, two trailing commas removed and the raw line break escaped as \n.
Repair never edits the text inside a valid string, and it only reports success when JSON.parse accepts the result. It does not guess at NaN, undefined, a stray " inside a string or two JSON values pasted one after the other. In those cases it stops, selects the spot and leaves your input as it was. When a reply was cut off at the model's output limit, the closed-up JSON is valid but incomplete, so check the last items before you use it.
What does "Unexpected non-whitespace character after JSON" mean?
It means the parser read one complete JSON value and then found more text after it. A JSON document holds exactly one value, so anything after the closing brace or bracket other than spaces and line breaks is an error. Worked example: {"name":"Ada","age":36} Let me know if you need anything else. makes current Chrome and Node report Unexpected non-whitespace character after JSON at position 24 (line 1 column 25). Position 24 is the L of “Let”, the first extra character, counted from 0. Firefox words the same error as JSON.parse: unexpected non-whitespace character after JSON data.
LLM replies cause it in three ways: a sentence after the JSON, a closing ``` fence left over from a markdown block, or two JSON objects in a row, which happens when several responses are joined or a JSON Lines file is parsed as one document.
Repair handles the first two. It removes the trailing sentence or fence and tells you exactly what it removed. Two objects in a row are a choice only you can make, so Repair stops and says so: wrap them in [ ] with a comma between them, or format them one at a time. In your own code, the lasting fix is to ask the model for JSON only, use the provider's structured output mode where it has one, and cut the text down to the first complete value before you call JSON.parse.
Common pitfalls
Most JSON debugging time is not spent on the parser error itself. It is spent on the assumptions we carried into the payload: that comments survive the wire, that numbers round-trip, that key order is preserved, that one editor's line endings match another's. Four pitfalls account for the bulk of the production incidents we have triaged.
- Trusting
JSON.parseto silently re-order nothing. ECMAScript specifies thatJSON.parsepreserves insertion order on object properties (modulo integer-like keys, which sort numerically). Downstream consumers that depend on a canonical key order break the moment a serializer rewrites in alphabetical order: signature verification over canonical JSON (RFC 8785, JCS), content-addressed storage, and merkle-rooted audit logs all fail when the same logical document hashes to two different digests. We never re-sort keys here for that reason. - Pasting JSON-with-comments (JSONC) and wondering why it fails. RFC 8259's grammar has no comment syntax, so
//and/* */are rejected. Atsconfig.jsonordevcontainer.jsonpasted straight into a strict parser raises an error at the first comment character. The fix is to strip comments first (a one-liner regex, or Microsoft'sjsonc-parsernpm package) or switch to a JSON5 parser if trailing commas are also in play. - Treating numbers loosely. JavaScript's
JSON.parsereads every number as an IEEE 754 double (the JSON spec itself sets no precision), with a safe-integer range of -2^53+1 to 2^53-1 (Number.MAX_SAFE_INTEGER is 9,007,199,254,740,991). The literal1e308parses cleanly, but multiplying it overflows toInfinity, which is not legal JSON and serializes tonull. Snowflake IDs and 64-bit timestamps lose precision silently above 2^53. We ship them as strings. - Putting a real line break inside a string. RFC 8259 section 7 on strings says the control characters U+0000 through U+001F must be escaped, so a line break between the quotes has to be written as the two characters
\n(or\r\nfor a Windows line ending), and a tab as\t. A raw line break or tab is invalid: in Chrome and Node,JSON.parsethrowsBad control character in string literal, and Safari reportsUnterminated string. LLMs hit this often when they write multi-line text into a JSON field. The escaped forms are fine, but an escaped\r\nstill reaches the consumer as CRLF, and some log-aggregator rules, YAML loaders and shell heredocs break on the CR. We normalize to\non write in any pipeline that crosses Windows and Unix.
When to use this tool
We built the formatter for three concrete workflows we kept hitting ourselves. The first is a backend dev debugging a 400 response from an upstream API. The vendor returns a 600-byte error envelope on a single line, the curl pipe in the terminal wraps it into an unreadable smear, and the on-call clock is ticking. Paste, reformat with 2-space indent, read the error.code and error.fields[] path in under ten seconds. The second is a reviewer reading a large config file in a code-review tab: a 4KB Kubernetes manifest, a Terraform state slice, or a feature-flag bundle that arrived minified from a teammate's test export. Reformatting before review surfaces the diff that matters and hides the whitespace noise that does not. The third is an ops engineer flattening multi-line logs into single-line minified format for log-aggregator ingestion. ELK, Datadog, and Splunk all expect one event per line, and a multi-line stack trace embedded inside a JSON event breaks line-based parsers without minification first. The same three workflows drive the keyboard shortcut layout in the tool: format, minify, and copy are all one click apart, because that is the rhythm we move at when we are actually using it.
Formatted JSON also makes field types easy to spot, and a few of them need a second tool. A value like "created_at": 1785628800 is a Unix timestamp in seconds, and the epoch converter turns it into a date (that one is August 2, 2026, 00:00 UTC). An id shaped like 550e8400-e29b-41d4-a716-446655440000 is a UUID, and when a test fixture needs fresh ones, the UUID v4 generator makes up to 100 at a time. A long run of letters, digits, + and / that ends in = is often Base64, which the Base64 decoder turns back into text.
Frequently asked
Does this formatter modify my data?
Only the whitespace, plus the normalization that JSON.parse and JSON.stringify always apply. Numbers and escapes are written in canonical form (1.0 becomes 1, \u0041 becomes A), and integer-like keys such as "2" and "1" move to the front in numeric order, which is how JavaScript orders object keys. Other keys keep their input order, and everything runs in your browser.
Why does my JSON have an 'Unexpected token' error?
Four mistakes cause nearly every case: a trailing comma after the last item, a missing comma between two fields, single quotes around strings, or unquoted object keys (fine in JavaScript, illegal in JSON). Modern browsers report the position and often the line and column, for example "Expected double-quoted property name in JSON at position 13 (line 1 column 14)". Check the character just before that position against the four patterns.
Can it handle JSON with comments (JSONC)?
No. RFC 8259 does not allow comments, so a strict parser rejects // and /* */. JSONC, used by tsconfig.json and VS Code settings, needs its own parser such as Microsoft's jsonc-parser, and JSON5 (trailing commas, single quotes, unquoted keys) isn't supported here either. The Repair button removes // and /* */ comments for you, along with trailing commas and other common slips.
Is it safe to paste sensitive data here?
Yes. Parsing and formatting run in your browser with JSON.parse and JSON.stringify, with no network request and no analytics on what you paste. The real risk is the screen: don't paste credentials during a screen share, into a screenshot for a ticket, or where someone can read over your shoulder.
What's the largest JSON file this can handle?
Files up to about 10MB format comfortably in a modern browser; syntax highlighting starts to feel slow on deeply nested files somewhere past 5MB. Beyond that, use a streaming tool such as jq --stream on the command line.
Sources: RFC 8259, the JSON standard · ECMA-404 · MDN on JSON.parse() · MDN on JSON.parse error messages. How we check our data