JSON Syntax Errors Explained: Causes and How to Fix Each
A complete reference for every JSON syntax error, with examples of broken JSON, the exact parser message, and the repair strategy.
Have broken JSON right now? Fix it free in under 1 second — no signup.
Fix My JSON →JSON syntax errors are notoriously unhelpful. "Unexpected token" or "Expected property name" tells you almost nothing about what's actually wrong. This guide explains every common JSON syntax error in plain English, shows you a real example of broken JSON, and tells you exactly how to fix it.
The JSON Specification in 30 Seconds
JSON (JavaScript Object Notation) follows RFC 8259. The rules that most commonly cause errors:
- Keys must be double-quoted strings —
{"name": "Alice"}, not{name: "Alice"} - Strings must use double quotes —
"hello", not'hello' - No trailing commas —
[1, 2, 3], not[1, 2, 3,] - No comments —
// commentand/ comment /are not valid JSON - Boolean and null are lowercase —
true,false,null(notTrue,False,None) - Numbers don't have leading zeros —
10, not010 - All brackets must be closed — unclosed
{,[, or"is invalid
Error Reference
"Unexpected token"
This is the most generic JSON error. It means the parser encountered a character it didn't expect at that position.
Common causes:// Comment at the start — invalid
{"key": "value"}
{
'name': 'Alice' // Single quotes — invalid
}
{
name: "Alice" // Unquoted key — invalid
}
Fix: Remove comments, replace single quotes with double quotes, quote all keys.
"Trailing comma"
{
"name": "Alice",
"age": 30, ← this comma has nowhere to go
}
[1, 2, 3,] ← same problem in an array
The last item in an object or array must not have a trailing comma. JavaScript allows this (as of ES2017), but JSON does not.
Fix: Remove the comma before} or ].
"Expected property name or '}'"
{
"name": "Alice",
, ← double comma
"age": 30
}
Or:
{
, ← leading comma
"name": "Alice"
}
Fix: Remove the extra or misplaced comma.
"Unexpected end of JSON input"
{
"name": "Alice",
"data": [1, 2, 3
The JSON ends before all brackets are closed. This usually means the JSON was truncated — cut off before completion.
{"message": "He said \
An unclosed string value also causes this.
Fix: Close all open strings, then close open brackets in reverse order (] before }).
"Property names must be double quoted"
{
name: "Alice" ← bare identifier, not a string
}
{
'name': "Alice" ← single-quoted key
}
JSON requires all object keys to be double-quoted strings. Neither bare identifiers nor single-quoted keys are valid.
Fix: Wrap all keys in double quotes:{"name": "Alice"}.
"Unexpected number" / "Expected comma or ']'"
[1 2 3] ← missing commas between values
{"a": 1 "b": 2} ← missing comma between properties
Fix: Insert commas between all values in arrays and between properties in objects.
"Bad Unicode escape sequence"
{"emoji": "\u00G1"} ← G is not a valid hex digit
{"path": "C:\Users\name"} ← \U and \n are interpreted as escapes
Backslashes in JSON strings are escape characters. \U is an invalid escape sequence. Windows file paths are a common source of this error.
"C:\\Users\\name", or use forward slashes: "C:/Users/name".
"Circular reference" / "Converting circular structure to JSON"
This error doesn't come from JSON parsing — it comes from JSON.stringify when you try to serialize a JavaScript object that references itself.
const obj = {};
obj.self = obj;
JSON.stringify(obj); // TypeError: circular structure
Fix: Remove circular references before serializing, or use a library like flatted that handles cycles.
Quick Reference: Python vs JSON Literals
If you're working with Python-originated data, watch out for these differences:
| Python | JSON |
|---|---|
True | true |
False | false |
None | null |
'string' | "string" |
Running Python's json.dumps() on a Python dict will give you valid JSON. The problems arise when data is printed with print(dict) or logged without json.dumps().
Tools for Debugging JSON Errors
- Browser DevTools Console —
JSON.parse(yourString)gives you a line/column number in Chrome. - AI JSONMedic Validator — paste JSON and get plain-English error explanations with line numbers.
- AI JSONMedic Fixer — paste broken JSON and get it automatically repaired with a diff of what changed.
- Python:
import json; json.loads(s)raises aJSONDecodeErrorwith line and column. - Node.js:
JSON.parse(s)throws aSyntaxErrorwith position info.
Prevention Checklist
Before treating JSON as valid, check:
- [ ] All keys are double-quoted
- [ ] All string values use double quotes
- [ ] No trailing commas
- [ ] No comments
- [ ] All brackets are closed
- [ ] Booleans and null are lowercase
- [ ] Backslashes in strings are properly escaped
For JSON generated by AI tools, always run it through a validator before using it in production.
For a complete reference on the most common parse error message, see the JSON Parse Error guide. If your JSON is coming from an LLM pipeline, the LLM JSON Repair Guide covers every AI-specific failure pattern with code fixes for Python and TypeScript.
FAQ
What does "Unexpected token" mean in a JSON error?
The parser found a character it didn't expect at that position. The character after "token" tells you what it found: Unexpected token ' means a single quote was used. Unexpected token T usually means True (Python boolean) was in the JSON. Unexpected token < means HTML was returned instead of JSON. The character position in the error points to the exact location in the string.
How do I find the exact line and column of a JSON syntax error?
Use a validator that reports position: Python's json.JSONDecodeError includes .lineno and .colno attributes. JavaScript's JSON.parse() error includes character position in the message. Online: paste into the JSON Validator for line-and-column error highlighting. For large files: python3 -m json.tool file.json reports the position in the error output.
What is the most reliable way to avoid JSON syntax errors when generating JSON programmatically?
Never build JSON by string concatenation or template literals — always use your language's native serialization: JSON.stringify() in JavaScript, json.dumps() in Python, json.Marshal() in Go. These handle escaping, quoting, and comma placement correctly. Only write JSON by hand for small static fixtures.
Why does valid-looking JSON fail to parse?
The most common invisible causes: BOM character at the start of the file (looks empty but isn't), CRLF line endings inside strings, non-standard Unicode whitespace characters that look like spaces, and invisible zero-width characters copy-pasted from a web page. Open the file in a hex editor or use xxd file.json | head to check the raw bytes.
Still dealing with broken JSON?
Paste it in and get it fixed in under 1 second — free, no signup, no install. Works with ChatGPT, Claude, n8n, and any AI output.
Fix My JSON Free →Related Articles