JSON is the format APIs, config files and data exports all speak, and it looks forgiving. It reads like plain text, the punctuation is minimal, and most files are short enough to eyeball. Then a parser rejects one, and the error points at a file that looks perfectly fine to you.
The gap is that JSON has a small, strict grammar, and parsers enforce every rule of it. A missing comma, a single quote where a double quote belongs, one comma too many at the end of a list: each is enough to stop the parse completely. This guide walks through the grammar rule by rule, then the strictness traps that break real files, using the free JSON Formatter and Validator on Ovatly to check each one. It runs in your browser, and nothing you paste is uploaded.
Contents
- Quick answer
- The grammar: objects and arrays
- Keys and values: what is allowed
- Commas separate items, they do not end them
- The strictness list: mistakes that break parsers
- How to check a file, step by step
- Worked example: a one-line object, formatted
- Limitations and honest tradeoffs
- Common mistakes
- FAQs
- Conclusion
- References
Quick answer
JSON has six building blocks: objects in curly braces, arrays in square brackets, strings in double quotes, numbers, the literals true, false and null, and commas that separate items. Keys are always double-quoted strings. There is no comma after the last item, no single-quoted strings, no unquoted keys and no comments. Break one of those rules and a strict parser rejects the whole file, not just the line. Paste any JSON into the JSON Formatter and Validator and use Validate to get a plain-words error naming the problem, or Format to pretty-print valid JSON with a 2 or 4 space indent.
The grammar: objects and arrays
An object is a set of key and value pairs inside curly braces. A colon sits between each key and its value, and a comma sits between each pair. An array is an ordered list of values inside square brackets, again separated by commas. The two nest freely: an object can hold arrays, an array can hold objects, and that nesting is how JSON describes almost everything.
{
"name": "Ovatly",
"tags": ["tools", "free"]
}
That is the whole structure. Every JSON document, however large, is those two containers and the value types below, repeated. When a file fails to parse, it is almost never structural confusion; it is one small rule broken inside this simple shape.
Keys and values: what is allowed
Keys are always strings, and strings in JSON always use double quotes. A key that looks like a plain word still needs them: "name", never name. Values come in exactly six types: a string in double quotes, a number, the boolean literals true and false, null, an object, or an array.
That short list is also a list of absences. JSON has no date type, no undefined, no functions, and no way to write a number as a fraction or a hex value. Numbers are plain decimal notation. If data needs something richer, it travels as a string and the receiving program interprets it, which is why dates in JSON are quoted text.
Commas separate items, they do not end them
The comma rule causes more rejected files than any other. A comma belongs between two items and nowhere else: not before the first item, and not after the last one. The grammar treats a comma as a promise that another item follows. A comma directly before a closing brace or bracket breaks that promise, and the parser stops.
This feels pedantic because many nearby formats are relaxed about it: JavaScript object literals accept a trailing comma, and so do some config formats. JSON does not, and copied files carry the extra comma with them. Our companion guide on trailing commas in JSON takes that single mistake apart in full.
The strictness list: mistakes that break parsers
Four traps account for nearly every invalid file this tool sees:
- Trailing commas. A comma after the last item in an object or array, as covered above. The single most common failure.
- Single-quoted strings. Writing
'name'instead of"name". JavaScript allows both; JSON allows only double quotes, for keys and string values alike. - Unquoted keys. Writing
name: "Ovatly"instead of"name": "Ovatly". Again, legal in JavaScript, illegal in JSON. - Comments. Lines starting with
//or blocks in/* */. JSON has no comment syntax at all, so a commented config file is not JSON, however reasonable it looks. The JSONC format permits comments, but strict JSON does not.
Notice the pattern: three of the four come from writing JSON as if it were JavaScript. The formats are cousins, not twins, and the parser only honours the JSON rulebook.
How to check a file, step by step
- Open the JSON Formatter and Validator and paste your JSON into the box.
- Click Validate only. This checks the text without changing a character of it, and reports the result.
- If the file is invalid, read the error. It names the problem in plain words, such as an unexpected character or a missing comma.
- Fix that one problem and validate again. A parser stops at the first error it meets, so a file with three problems needs three rounds.
- Once the file is valid, use Format to pretty-print it with a 2 or 4 space indent for reading, or minify it to one line for compact storage.
Worked example: a one-line object, formatted
Take this compact object, exactly as an API might return it:
{"name":"Ovatly","tools":250,"free":true}
Run through the grammar: braces make it an object, every key is a double-quoted string, the values are a string, a number and a boolean, and commas sit between the pairs only. Valid. Formatting it produces the indented version:
{
"name": "Ovatly",
"tools": 250,
"free": true
}
Same data, same rules, just laid out so a human can scan it. Add a comma after true in either version and the file becomes invalid instantly, which is the strictness list in action.
Limitations and honest tradeoffs
The strictness is the point of JSON, but it cuts both ways. A config file written for a JSONC parser, comments and all, will fail here, and the fix is to strip the comments rather than argue with the standard. The tool also reports the problem but leaves the edit to you: it names what is wrong, and you change the text.
Number handling follows JavaScript, so an integer beyond 2^53 can lose exactness when text is reformatted. Validate only never reformats, which is why it is the safer choice for files carrying long IDs. Finally, very large pastes, in the tens of megabytes, may take a moment to process, since everything happens locally in the tab.
Common mistakes
- Writing JSON like JavaScript. Single quotes, unquoted keys and trailing commas all feel natural to anyone who writes code, and all three are invalid here.
- Adding comments to a .json file. There is no comment syntax to use. Keep notes in a separate file.
- Assuming a near miss still parses. One broken rule rejects the entire file, not just the line with the problem.
- Reformatting files with long ID numbers. Formatting can round an integer past 2^53. Validate only when exact digits matter.
- Eyeballing a long file instead of validating it. The plain-words error finds the problem faster than reading does.
FAQs
What are the basic building blocks of JSON? Objects in curly braces, arrays in square brackets, and values that are strings, numbers, booleans, null, or another object or array. Commas separate the items inside objects and arrays.
Do JSON keys always need quotes? Yes. Every key is a string in double quotes, even a key that looks like a plain word. Unquoted keys are one of the most common reasons a file copied from JavaScript code fails to parse as JSON.
Why does my JSON file with comments in it fail validation? Comments are not part of the JSON standard at all. Formats such as JSONC allow them, but a strict JSON parser rejects the file. Remove the comments, or keep them in a separate notes file.
What is the difference between Format and Validate in the tool? Validate only checks the text and reports any problem in plain words, without changing a character. Format rewrites valid JSON with a 2 or 4 space indent for reading, and can also minify it to one line.
Are very long numbers safe in JSON? Mostly, with one caveat. Number precision follows JavaScript, so an integer beyond 2^53 can lose exactness when the text is reformatted. Validate only does not reformat, so use it when an exact long ID matters.
Conclusion
JSON rewards precision: six building blocks, double quotes on every key and string, commas strictly between items, and no comments or trailing commas anywhere. Hold those rules and parsers stop being mysterious. When a file still fails, the JSON Formatter and Validator names the problem in plain words so the fix takes seconds. For the deepest single trap, read the companion guide on trailing commas in JSON, and browse the full set in our Data and JSON Tools guides.
References
- ECMA-404, the JSON data interchange standard: https://ecma-international.org/publications-and-standards/standards/ecma-404/
- MDN Web Docs, on JSON syntax and working with JSON: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON