JSON Formatting & Validation: Fixing Common Errors
JSON's rules are simple, strict, and unforgiving of exactly the habits every other language lets you get away with.
What JSON is
JSON (JavaScript Object Notation) is a plain-text format for structured data. It has exactly six value types: string (in double quotes), number, boolean (true/false), null, array ([ ]), and object ({ }, a set of "key": value pairs). That's the entire specification. Its appeal is that it's both human-readable and trivially parsed by every programming language, which is why it became the default format for web APIs and configuration files.
The strict rules that trip people up
JSON borrows JavaScript's look but not its leniency. These are all valid in JavaScript and invalid in JSON:
- Trailing commas.
[1, 2, 3,]— the comma after3is a syntax error. Same for the last property in an object. - Single quotes.
{'name': 'value'}— JSON strings and keys must use double quotes. - Unquoted keys.
{name: "value"}— the keynamemust be"name". - Comments.
// like thisor/* like this */— JSON has no comment syntax at all. - Undefined, functions, NaN, Infinity. None of these exist in JSON. Only the six types above.
- Leading zeros or a bare leading decimal point in numbers.
.5and012are invalid; write0.5and12.
A single one of these anywhere in the document makes the entire thing fail to parse — there's no partial validity.
Reading a parser error
A good validator tells you the line and column where parsing failed. The key thing to know: the error location is where the parser noticed a problem, which is often just after the actual mistake. "Unexpected token } at line 12" frequently means a missing comma at the end of line 11, not a problem with the brace itself. When the reported line looks fine, check the end of the previous line for a missing comma, and scan back for an unclosed bracket or quote.
Formatting, minifying and validating — three different jobs
- Validating answers one question: is this valid JSON? A validator parses the text and either confirms it's well-formed or points to the first error.
- Formatting takes valid JSON and re-prints it with consistent indentation (usually 2 or 4 spaces) and line breaks, so the nesting structure is visible at a glance. Essential when you're handed a single-line blob from an API and need to actually read it.
- Minifying does the reverse: removes every non-essential space and line break to produce the smallest byte count, for sending over a network or embedding in code. The data is unchanged — a minified file re-formatted is identical to the original formatted version.
Format or validate your JSON now
ToolQiva's JSON Formatter validates as you type, points to the exact line and column of any error, and switches between a formatted view and a collapsible tree view. JSON Validator is the focused check-only version, and JSON Minifier produces the compact single-line output. All three run entirely in your browser — nothing you paste is sent anywhere.
Frequently asked questions
What's the difference between formatting and minifying JSON?
Formatting (also called beautifying or pretty-printing) adds indentation and line breaks so a human can read the structure. Minifying strips all of that whitespace to make the smallest possible file for transmission or storage. Both preserve the exact same data — they're two views of the identical JSON.
Why is my JSON invalid when it looks fine?
The most common culprits, in rough order: a trailing comma after the last item in an array or object; single quotes instead of double quotes; unquoted object keys; a comment (JSON has no comments at all); or a missing comma between items. JSON's parser is strict — one of these anywhere makes the whole document invalid.
Can JSON have comments?
No. The JSON specification has no comment syntax whatsoever — not // and not /* */. If you need commentary in a config file, either use a format that allows it (like YAML or JSON5) or keep a separate documentation file. Some tools accept "JSON with comments" as an extension, but standard JSON parsers will reject it.
Is JSON the same as a JavaScript object?
Close, but not identical. JSON is a text format inspired by JavaScript object syntax, but it's stricter: keys must be double-quoted strings, strings must use double quotes, no trailing commas, no functions, no undefined, and no comments. Every valid JSON document is valid JavaScript, but the reverse isn't true.