How to Fix the Most Common JSON Errors
Developer · Published October 2, 2026 · Updated October 24, 2026 · 4 min read
Written by Akinrinmade Michael
JSON looks like JavaScript, which is why so many people write invalid JSON by accident. Parsers are strict: one wrong character and the whole document is rejected. The good news is that a short list of mistakes causes nearly every error, and each one has a quick fix.
The mistakes at a glance
| Mistake | Wrong | Right |
|---|---|---|
| Trailing comma | {"a": 1,} | {"a": 1} |
| Single quotes | {'a': 'x'} | {"a": "x"} |
| Unquoted key | {a: 1} | {"a": 1} |
| Comment | {"a": 1 // note} | Remove it |
| Missing comma | {"a": 1 "b": 2} | {"a": 1, "b": 2} |
| Undefined or NaN | {"a": undefined} | {"a": null} |
| Raw line break in a string | A real new line inside quotes | Write \n |
1. A trailing comma
JavaScript allows a comma after the last item, and JSON doesn't. This one is easy to create when you delete the last line of a list and leave the comma on the line above.
{ "name": "Ann", "age": 30, } (wrong)
{ "name": "Ann", "age": 30 } (right)2. Single quotes
Strings and keys must use double quotes. Text copied from a word processor can also contain curly quotes, which look right on the screen and are different characters to a parser. Retype them or replace them with straight quotes.
{ 'name': 'Ann' } (wrong)
{ "name": "Ann" } (right)3. Unquoted keys
A JavaScript object literal lets you write { name: "Ann" }. JSON wants the key in double quotes every time.
4. Comments
JSON has no comments. Remove // and /* */ lines, or store notes in a normal field such as "_comment". If your file has comments and works in your editor, it's probably JSONC or JSON5, which are looser formats that need their own parser.
5. Missing commas or brackets
Every item in an object or list is separated by a comma, and every { and [ needs a matching closing character. Long documents hide a missing bracket easily, and the error often shows up at the very end of the file, far from the real cause. A formatter that indents the document helps, because the line where the indentation goes wrong is usually next to the mistake.
6. Special values and unescaped characters
undefined,NaNandInfinityaren't valid values. Usenullor a string.- A line break inside a string must be written
\n, and a quote inside a string must be written\". - A backslash must be doubled:
"C:\\temp". Windows paths are a common source of errors. - Numbers can't have leading zeros (
007) or a trailing dot (1.). Write 7 or "007". - Hex numbers like
0xFFaren't allowed.
Problems you can't see
- A byte order mark. Some editors add an invisible character at the very start of a file, and some parsers reject it. If the error is at line 1, column 1 and the file looks fine, this is the likely cause.
- Non-breaking spaces. Copied from a web page, they look like spaces and are different characters.
- Empty input. An empty string isn't valid JSON, though a single value like
42or"hi"is. - Two documents in one. A file with several JSON objects one after another, as in log files, is JSON Lines, not one JSON document. Parse it a line at a time.
Valid but surprising
Some things parse fine and still cause trouble. Duplicate keys are allowed, but the parser keeps only the last one, so earlier values vanish. Integers larger than 9,007,199,254,740,991 lose their last digits in JavaScript, so send long ids as strings. And a number written as 1.0 can come back as 1.
Reading the error message
Error messages give a position, as a line and column or a character count. The reported spot is where the parser gave up, which is sometimes just after the real mistake. If the message points at the start of a key, look at the end of the line before it for a missing comma. Messages differ between parsers. A browser might say it hit an unexpected token, and another tool might say it expected a comma or a closing brace. They all mean the same thing: the character at that position doesn't fit.
How to fix it
- Paste the JSON into the JSON Formatter.
- Read the line and column it reports and fix that one problem.
- Repeat until it says "Valid JSON", then click Prettify.
- If the document is huge and you can't find the fault, cut it in half and test each half. The half that fails contains the mistake. Repeat until you find it.
- Compare the fixed version with the original using JSON Diff if you want to be sure nothing else changed.
Stopping errors at the source
Don't build JSON by joining strings in code. Build the data as an object and let the language write the JSON, such as JSON.stringify(data, null, 2) in JavaScript or json.dumps(data, indent=2) in Python. The library handles quotes, escapes and commas for you. Once your JSON is valid, you can pull values out of it with the JSONPath tester or describe its shape with the JSON schema generator.