How to Fix Common JSON Errors
JSON parsers are unforgiving by design: one misplaced character and the whole document is rejected with a message like Unexpected token } in JSON at position 47. The good news is that the same handful of mistakes cause nearly all failures. This guide shows each one — broken example, then fix — roughly in order of how often they happen.
Reading the error message first
Unexpected token X at position N means the parser was fine until character number N, where it met something the grammar forbids. The mistake is usually at that position or just before it — a missing comma two lines up makes the parser choke on the next token. Paste the document into the JSON Validator and it converts the position into a line and column number for you.
1. Trailing commas
{ "name": "Ada", "age": 36, } ✕
{ "name": "Ada", "age": 36 } ✓JavaScript tolerates a comma after the last item; JSON never does. This is the single most common error, especially in hand-edited config files. Delete the comma after the final member of every object and array.
2. Single quotes
{ 'name': 'Ada' } ✕
{ "name": "Ada" } ✓All strings — keys and values — must use double quotes. Single quotes usually arrive via copy-paste from Python or JavaScript source code.
3. Unquoted keys
{ name: "Ada" } ✕
{ "name": "Ada" } ✓Object keys are strings and need quotes, even simple ones. JavaScript object literals allow bare keys, which is why code snippets pasted as JSON fail this way.
4. Comments
{
// user record ✕
"name": "Ada"
}JSON has no comment syntax at all. Some tools accept a superset called JSONC (VS Code’s settings, for example), but any standard parser rejects comments. If a config format needs commentary, either remove the comments before parsing or store an ignored key like "_comment".
5. Unescaped characters inside strings
{ "quote": "She said "hi"" } ✕
{ "quote": "She said \"hi\"" } ✓Double quotes, backslashes and real line breaks inside a string must be escaped as \", \\ and \n. This bites hardest when embedding code, file paths (Windows backslashes!) or multi-line text as a value. The JSON Escape tool applies the correct escaping mechanically.
6. Wrong values: undefined, NaN, Infinity
{ "score": NaN, "next": undefined } ✕
{ "score": null, "next": null } ✓These exist in JavaScript but not in JSON. The only "empty" value JSON knows is null; the only numbers are finite ones.
7. Smart quotes and invisible characters
Text that passed through Word, Google Docs or a chat app often carries typographic quotes (“ ”) instead of straight ones, or an invisible byte-order mark (BOM) at the start of the file. Both are invisible to the eye and fatal to the parser. Re-type the quotes in a code editor, and save files as UTF-8 without BOM.
A reliable debugging routine
Validate, read the line number, fix the first error, repeat — parsers stop at the first problem, so a document with three mistakes takes three rounds. Once the document parses, run it through the JSON Formatter: properly indented structure makes any remaining logical issues (a value in the wrong place, a misspelled key) much easier to see. And if you are new to the format’s rules in general, start with What Is JSON? — most syntax errors stop happening once the six value types are second nature.