JSON looks simple until a single missing comma or stray quote breaks a build. This guide covers the syntax rules a formatter enforces, the errors it catches, and how to read the output.
On this page
What "formatting" JSON actually does
Formatting takes JSON text - valid or not visually organized - and re-serializes it with consistent indentation and line breaks, so nested objects and arrays are easy to scan. It does not change the data: the same keys, values, and structure go in and come back out, only the whitespace around them changes. A separate step, validation, checks whether the text is syntactically legal JSON in the first place; a formatter that also validates will refuse to reformat text that fails that check and instead reports where it broke.
The rules JSON syntax enforces
- Object keys must be double-quoted strings - single quotes and unquoted keys are invalid JSON, even though both are legal in JavaScript object literals.
- Trailing commas are not allowed after the last item in an array or the last property in an object.
- Strings must use double quotes; escape a literal double quote inside a string as \".
- Numbers cannot have leading zeros (01 is invalid) and cannot be NaN, Infinity, or written as hex.
- Every opening brace, bracket, and quote needs a matching close - the most common real-world failure is one of these left unclosed after editing by hand.
Before and after: a typical minified API response
APIs commonly return JSON with no whitespace at all, which is efficient to transmit but unreadable to a person debugging a response. Formatting with 2-space indentation turns this:
{"id":1,"name":"Ada Lovelace","roles":["admin","editor"],"active":true}into this:
{
"id": 1,
"name": "Ada Lovelace",
"roles": [
"admin",
"editor"
],
"active": true
}Common errors and what they mean
| Error message pattern | Typical cause | Fix |
|---|---|---|
| Unexpected token } / Unexpected end of JSON input | A trailing comma before a closing brace or bracket, or a value cut off mid-edit | Remove the trailing comma, or complete the truncated value |
| Unexpected token ' | Single-quoted string or key (valid in JS, not in JSON) | Replace single quotes with double quotes |
| Unexpected non-whitespace character after JSON | Two JSON values concatenated (e.g. two objects pasted back to back) instead of one root value | Wrap them in an array, or format them one at a time |
| Bad control character in string literal | A raw newline or tab pasted inside a string instead of the escaped \n / \t | Escape the character or remove it |
Frequently asked questions
No - the parsing and formatting happen locally in your browser’s JavaScript engine, not on a server. That matters in practice because people often paste things here that shouldn’t leave their machine: a production API response with real customer data, an internal config file with connection strings, or an auth token buried in a payload. None of it is transmitted anywhere; it’s the same as opening the text in a local editor.
The validator shows the specific parsing error and its position, most commonly a missing comma, an unclosed bracket, or a trailing comma before a closing brace.
Yes - use the "Minify input" button to collapse your JSON to a single compact line, useful for reducing payload size before sending it over the wire.