Common JSON Syntax Errors: Trailing Commas, Missing Quotes, and How to Fix Them

JSON is unforgiving. One misplaced comma, one missing quotation mark, one unescaped backslash, and the entire file refuses to parse. The error message from most parsers gives you a line number but rarely tells you what the actual problem is. Here are the errors developers hit most often and exactly how to fix them.

1. Trailing Commas

This is the single most common JSON error, especially for developers coming from JavaScript, Python, or most modern programming languages where trailing commas are permitted or even preferred.

Invalid JSON:

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

Valid JSON:

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

The fix: remove the comma after the last item in any object or array. JSON strict specification does not permit trailing commas.

2. Unquoted Keys

JSON requires all object keys to be strings enclosed in double quotes. This is different from JavaScript object literal syntax, which allows unquoted keys.

Invalid: {name: "Alice"}

Valid: {"name": "Alice"}

3. Single Quotes Instead of Double Quotes

JSON only accepts double quotation marks for strings. Single quotes cause an immediate parse failure.

Invalid: {'name': 'Alice'}

Valid: {"name": "Alice"}

Paste your broken JSON and fix it instantly. The formatter shows exactly where the error is and lets you copy the corrected version.

Open JSON Formatter

4. Unescaped Special Characters in Strings

Certain characters inside JSON string values must be escaped with a backslash. The most common are:

Invalid: {"message": "He said "hello""}

Valid: {"message": "He said \"hello\""}

5. Wrong Data Types

JSON supports six specific data types: string, number, boolean (true/false), null, array, and object. True and false must be lowercase. Null must be lowercase. Undefined is not a valid JSON value.

Invalid: {"active": True, "value": undefined}

Valid: {"active": true, "value": null}

6. Mismatched Brackets and Braces

Every opening { needs a closing }. Every [ needs a ]. For complex nested JSON, brackets often get lost especially when editing manually. A formatter with bracket highlighting makes these errors immediately visible.

The Fastest Way to Debug JSON

Paste the JSON into a formatter that validates in real time. A good formatter will highlight the specific problem character and line without you needing to count brackets manually. Once the JSON is clean, use the prettify function so the structure becomes visually scannable before saving or sending.

Comments Are Not Allowed

This one catches almost everyone at least once. JSON has no comment syntax at all. Neither double slashes nor slash-star blocks are valid, even though your editor will happily let you type them and will probably colour them correctly on the way in. If you need to annotate a config file, add a real key such as "_comment", or move to a format that supports comments like YAML, and strip it before anything strict reads the file.

Single Quotes and Unquoted Keys

JSON wants double quotes on both keys and string values. Single quotes are a JavaScript habit that does not carry across. Unquoted keys are the same story. Writing {name: "Ada"} gives you a perfectly valid JavaScript object literal and a completely invalid JSON document. Parsers tend to point at the character just after the offending key, which makes the error look like it is in the wrong place.

Values That Do Not Exist in JSON

NaN, Infinity and undefined are all fine in JavaScript and none of them exist in JSON. Serialising an object containing them either throws or quietly converts them to null, depending on which tool you are using. If numbers are turning into nulls somewhere between two systems, start here.

Trailing commas belong to the same family of things JavaScript forgives and JSON does not. A comma after the final item in an array or object is a hard syntax error.

Encoding and the Invisible BOM

A byte order mark at the start of a UTF-8 file is invisible in most editors and fatal to some strict parsers. The error message is rarely helpful. You get something about an unexpected token at position 0, while position 0 looks like an entirely normal opening brace. If a file suddenly parses after you retype the first line, a BOM was sitting there.

Duplicate Keys and Number Precision

Duplicate keys are technically permitted by the specification, but the behaviour is undefined. Most parsers keep the last occurrence and discard the others without a word. That is a very quiet way to lose data.

Large integers are the other silent problem. JSON itself sets no precision limit, but JavaScript parses numbers as doubles, so anything above roughly nine quadrillion starts losing accuracy. Database IDs and snowflake-style identifiers are the usual casualties. Send those as strings.

How to Read the Error Message

A parser error gives you a position, not a diagnosis. The character it reports is where the parser gave up, which is often slightly after the point where you actually made the mistake. Work backwards from there and check three things: the nearest closing bracket, the nearest comma, and the nearest quote. One of those three is nearly always the culprit.