Developer Tools

Fix Invalid JSON: The 5 Errors That Break Every Payload

By Huzaifa UmerJuly 2, 20265 min read

JSON is strict on purpose, and its parser fails loudly at the first rule it sees broken. The good news: in practice, almost every invalid payload is one of the same five mistakes. Learn these and you can fix most JSON errors on sight.

1. The trailing comma

JSON forbids a comma after the last item. This is the single most common error, because JavaScript allows it and JSON does not.

Broken: {"name": "Alice", "age": 30,}

Fixed: {"name": "Alice", "age": 30}

Delete the final comma and the payload parses.

2. Single quotes

Every string and every key in JSON must use double quotes. Single quotes are valid in JavaScript and Python, which is exactly why they sneak into JSON so often.

Broken: {'name': 'Alice'}

Fixed: {"name": "Alice"}

3. Unquoted keys

Object keys must be quoted strings, always. Writing keys bare, JavaScript style, fails immediately.

Broken: {name: "Alice"}

Fixed: {"name": "Alice"}

4. Comments

JSON has no comment syntax at all. Both // line comments and /* block comments */ make a file invalid the moment they appear. If a config format you use does allow comments, it is a JSON superset like JSONC, not JSON itself. Before pasting into anything that expects real JSON, strip the comments.

5. Missing or mismatched brackets

Every { needs its } and every [ needs its ]. In a payload nested four levels deep, a single missing brace produces an error message pointing at the end of the file, far from the actual mistake. Indentation is the antidote: a properly formatted payload makes the structure visible, and the missing bracket jumps out.

Let the parser find it for you

Hunting these by eye in a 4,000 character single line API response is miserable. Paste the payload into the free JSON Formatter instead: it validates with the same JSON.parse engine your application uses, shows the exact parser error when something is wrong, and pretty prints the structure so nesting problems become visible. If it parses there, it will parse in your code.

The bottom line

Trailing commas, single quotes, bare keys, comments, and lost brackets. Five errors, five fixes, and a validator that points at the exact line. Invalid JSON stops being a mystery once you know the list.

FAQ

Why is my JSON invalid?
The most likely causes are a trailing comma after the last item, single quotes instead of double quotes, unquoted keys, comments, or a missing bracket. A validator will show the exact parser error.
Are comments allowed in JSON?
No. JSON has no comment syntax. Formats that allow comments, like JSONC, are supersets of JSON, and their files fail in a strict JSON parser.
Why does JavaScript accept my object but JSON rejects it?
JavaScript object syntax is looser: it allows single quotes, unquoted keys, and trailing commas. JSON requires double quoted keys and strings and forbids trailing commas.
How do I find a missing bracket in a large JSON file?
Pretty print the payload with a formatter. Correct indentation makes the structure visible, and the unbalanced brace or bracket becomes easy to spot.
Can a tool fix my JSON automatically?
Validators point at the exact error rather than guessing your intent, because an automatic repair could silently change your data. The fix is usually a one character edit.

Related Tools

About the Author

Huzaifa Umer writes practical guides on documents, file formats, and everyday web tools at The Tools Kit. He focuses on plain answers that save readers time.

View all posts by Huzaifa Umer →
← Back to Blog