Malformed JSON has a way of failing at the worst possible moment — a third-party API returns a truncated response, a hand-edited config file gets a stray comma, or a log export gets cut off mid-write. The good news: JSON's syntax is simple enough that most breakage falls into a small, predictable set of mistakes, and most of them are quick to fix once you know what you're looking for.
The five JSON errors you'll hit 90% of the time
1. Trailing commas
JSON does not allow a comma after the last item in an object or array — even though it's legal in JavaScript, which trips up a lot of people copying data between the two.
{ "name": "file2fix", "active": true, } ❌ trailing comma before }
{ "name": "file2fix", "active": true } ✅ correct
2. Unescaped quotes inside strings
A double quote inside a string value has to be escaped as \". This is the classic failure mode when JSON gets built by naive string concatenation instead of a proper serializer.
{ "note": "he said "hello"" } ❌ breaks parsing
{ "note": "he said \"hello\"" } ✅ correct
3. Single quotes instead of double quotes
JSON requires double quotes for both keys and string values — always. Single quotes are valid in JavaScript object literals but not in JSON itself.
{ 'name': 'file2fix' } ❌ invalid JSON
{ "name": "file2fix" } ✅ correct
4. Unbalanced brackets or braces
Usually caused by a truncated API response or a copy-paste that missed the last few characters. The parser error ("Unexpected end of JSON input") is your clue — it means the structure never closed.
5. Missing commas between properties
Easy to miss visually, especially in deeply nested or minified JSON, since the two tokens on either side of the gap look perfectly valid on their own.
{ "a": 1 "b": 2 } ❌ missing comma
{ "a": 1, "b": 2 } ✅ correct
Why "just read the error message" often isn't enough
Most JSON parsers report only the position of the first error, not every problem in the file. Fix that one and re-run, and you'll often hit a second, unrelated error a few lines later — which makes manually fixing a large malformed file (say, a multi-thousand-line API log dump) slow and frustrating one error at a time.
The faster path: automated repair
For anything beyond a two-line fix, it's faster to run the file through a repair tool that finds and corrects all of the common failure patterns — missing commas, unbalanced brackets, unescaped quotes — in one pass, rather than playing whack-a-mole with a linter. Our Broken JSON Auto-Repair tool was built specifically for this: paste in malformed JSON from a broken API response, a corrupted export, or a hand-edited config, and it fixes the structural issues and hands back valid JSON you can actually use.
Preventing it next time
- Always generate JSON with a real serializer (
json_encode()in PHP,JSON.stringify()in JS) — never string-concatenate it by hand. - If you're hand-editing config files, run them through a validator before deploying, not after something breaks in production.
- When consuming a third-party API, don't assume the response is always well-formed — wrap your parsing in a try/catch and log the raw response so you have something to repair if it ever comes back malformed.