Every backend developer has been there: an API returns something that looks like JSON but isn't quite right. You paste it into a JSON formatter, click format, and see a red error — "JSON parse error: line 3, column 15."
JSON format errors are one of the most common yet frustrating problems in development. Over the years, I have run into countless cases. Here are 5 tips I use regularly.
Tip 1: Check your commas — too many or too few
Comma issues account for at least half of all JSON errors. Two types: trailing comma (a comma after the last element, like [1, 2, 3,]) and missing comma (between two elements).
When debugging JSON, I always check commas first. If the error points near the end of a line, it is probably a comma issue.
Tip 2: Keys must use double quotes
JavaScript objects allow unquoted keys (like {name: "John"}), but JSON requires double quotes: {"name": "John"}. This is a common mistake when copying JavaScript objects directly as JSON.
Simple rule: if you see unquoted or single-quoted keys, it is not valid JSON. Use our JSON Formatter to validate quickly.
Tip 3: Escape special characters in strings
If a JSON string contains double quotes, backslashes, or newlines, they must be escaped. For example, he said "hello" must be written as "he said \"hello\"" in JSON.
Always use JSON.stringify() to generate JSON instead of manual string concatenation. This automatically handles escaping for you.
Tip 4: Numbers don't need quotes, and no leading zeros
{"age": 25} stores age as a number, not a string. JSON also doesn't allow leading zeros — {"id": 01} is invalid and should be {"id": 1}.
Tip 5: Use an online validator
When you have a piece of JSON that won't parse, throw it into an online tool. A good JSON tool does three things: format (expand compressed JSON), validate (check syntax and point to errors), and minify (compress back to one line).
Our JSON Formatter supports all three, entirely in your browser.
Summary
JSON errors are annoying, but most come from a few common mistakes. Check commas, use double quotes for keys, escape special characters, handle numbers correctly — these four tips solve 90% of JSON problems.