Skip to main content
Developer & Security 6 min read

How to Debug Broken JSON: A Developer's Troubleshooting Checklist

SyntaxError: Unexpected token at position 847. Sound familiar? This checklist covers the most common JSON errors and how to fix them quickly.

MD
Meet Dhameliya

You paste JSON into your application and get SyntaxError: Unexpected token. The error message points to a character position deep inside a 500-line config file. You stare at the JSON and everything looks fine. This guide covers the most common causes of broken JSON and how to find and fix them in seconds.

1. Trailing Commas

The single most common JSON error. JSON does not allow a comma after the last item in an object or array. This is valid in JavaScript but invalid in JSON.

2. Single Quotes Instead of Double Quotes

JSON requires double quotes for both keys and string values. Single quotes, backticks, and unquoted keys are all invalid in strict JSON.

3. Comments in JSON

Standard JSON does not support comments — not // single-line nor /* */ block comments. If you need comments, use JSONC (supported by VS Code and TypeScript) or JSON5.

4. Unescaped Special Characters

Inside JSON strings, backslashes and double quotes must be escaped. Newlines and tabs must use escape sequences. Raw control characters will break parsing.

5. Missing Commas Between Properties

Every property-value pair in an object must be separated by a comma, except the last one. Missing a comma produces an unhelpful error pointing to the next property.

6. Invalid Value Types

JSON only supports: strings, numbers, booleans (true/false), null, objects, and arrays. JavaScript-specific values like undefined, NaN, Infinity, and Date objects are not valid JSON.

7. Invisible BOM Characters

Some text editors prepend an invisible BOM (Byte Order Mark) character at the start of files. This is invisible in most editors but causes parsing errors at position 0. Save files as UTF-8 without BOM.

How to Find Errors Quickly

Our JSON Formatter and Validator pinpoints the exact line and character position of JSON syntax errors. Paste your JSON, and it will highlight exactly what is wrong and where — much more useful than a generic error message.

Frequently Asked Questions

What does Unexpected token mean in JSON? expand_more
It means the JSON parser encountered a character it did not expect at that position. Common causes: trailing commas, single quotes, comments, unescaped special characters, or missing commas between properties. Use a JSON validator to find the exact location.
Why does my JSON work in JavaScript but fail in other languages? expand_more
JavaScript is more lenient with object literals — it accepts single quotes, trailing commas, and unquoted keys. But JSON.parse() and parsers in other languages follow strict JSON specification rules.
How do I find invisible characters in JSON? expand_more
Use a hex editor or a text editor that shows whitespace characters. Common invisible culprits: BOM characters (U+FEFF), non-breaking spaces (U+00A0), and zero-width spaces (U+200B). A JSON validator will flag these.

build Related Tools

MD

Meet Dhameliya

Founder & Product Manager

Computer Engineering graduate with 3+ years in IT. Meet built Utility Spark to create privacy-first browser tools that process your data locally — no uploads, no accounts.