How to Fix JSON Parse Error — Step by Step (With Examples)
A JSON parse error stops your app cold. Whether you are seeing SyntaxError: Unexpected token in the browser console, a failed API response parse in Node.js, or a broken config file, the root cause is almost always one of a small set of syntax mistakes. This guide shows you exactly how to fix a JSON parse error step by step — with real examples of every common case.
SyntaxError: Unexpected token
These messages all mean the same thing: the JSON parser hit a character it did not expect according to the JSON specification. The position number tells you roughly where the error is, but finding the cause requires knowing what to look for.
What Causes 'Unexpected Token' in JSON?
The JSON specification is intentionally strict. Unlike JavaScript, it does not tolerate comments, trailing commas, single quotes, or any shorthand. Here are the six most common reasons why JSON is invalid:
Trailing comma
A comma after the last element in an array or the last property in an object. Valid in JS5/JSON5, illegal in standard JSON.
Single quotes
Using single quotes ('value') instead of double quotes ("value") for strings or keys. The most common mistake from JavaScript developers.
Unquoted keys
Writing {key: "value"} instead of {"key": "value"}. Shorthand property names are valid JavaScript but not JSON.
Missing comma
Forgetting the comma between two object properties or two array elements. The parser reads the next value as unexpected.
Extra or mismatched bracket
An extra } at the end or a missing ] causes the parser to run off the expected structure.
Control characters in strings
Tab characters, raw newlines, or non-printable characters inside a string value that have not been escaped with \t or \n.
Trailing comma — the most common JSON error
Trailing comma after last property — invalid JSON
{
"name": "Alice",
"age": 30,
"role": "admin",
}No trailing comma — valid JSON
{
"name": "Alice",
"age": 30,
"role": "admin"
}Single quotes instead of double quotes
Single quotes — causes SyntaxError: Unexpected token
{'user': 'Bob', 'active': true}Double quotes — correct JSON format
{"user": "Bob", "active": true}How to Find a Missing Comma in JSON
A missing comma is one of the trickiest errors to spot by eye — especially in large JSON files. The parser error often points to the line after the missing comma, not the line where it belongs. Here is what it looks like:
Missing comma between object properties
Missing comma after 'Jane' — parser fails on 'lastName'
{
"firstName": "Jane"
"lastName": "Smith",
"email": "jane@example.com"
}Comma after each property except the last
{
"firstName": "Jane",
"lastName": "Smith",
"email": "jane@example.com"
}Pro tip
Online JSON error checkers highlight the exact line where the parser fails. This is much faster than reading error messages that say "position 142" — which requires counting characters manually.
Missing comma in an array
Missing comma between array elements
{
"tags": ["javascript" "typescript", "nodejs"]
}Comma between every array element
{
"tags": ["javascript", "typescript", "nodejs"]
}How to Fix a JSON Parse Error Step by Step
The fastest way to debug a broken JSON file is to paste it into an online JSON error checker that highlights exactly where the problem is. Here is the exact process:
Copy the broken JSON
Copy the entire JSON string — from the API response body, the config file, the log output, or wherever it came from. Select all and copy.
Paste into the JSON Fixer
Go to unblockdevs.com/json-fixer-online and paste your JSON into the input field. The tool immediately validates the JSON as you type.
Read the error highlighting
If the JSON is invalid, the fixer highlights the problematic line and shows a human-readable error message — not just a character position.
Apply the suggested fix
The JSON Fixer can auto-repair many common errors: it removes trailing commas, converts single quotes to double quotes, and quotes unquoted keys. Click Fix to apply.
Copy the fixed JSON
Once the JSON is valid, the right panel shows the corrected version. Copy it back to your project, API client, or wherever it needs to go.
Fix JSON parse errors instantly
Common JSON Syntax Errors and Fixes
Here are five of the most frequently encountered JSON syntax errors with before-and-after examples for each:
Unquoted object keys
Unquoted keys — valid JavaScript but invalid JSON
{
id: 1,
name: "Product A",
price: 19.99
}All keys must be double-quoted strings
{
"id": 1,
"name": "Product A",
"price": 19.99
}Comments in JSON
Comments are not valid JSON — strip them first
{
// API version
"version": "2.1",
/* base URL */
"endpoint": "https://api.example.com"
}Pure data only — no comments allowed
{
"version": "2.1",
"endpoint": "https://api.example.com"
}undefined and NaN values
NaN, undefined, Infinity — not valid JSON values
{
"count": NaN,
"result": undefined,
"ratio": Infinity
}Use null for missing/invalid numeric values
{
"count": null,
"result": null,
"ratio": null
}Unescaped double quotes inside strings
Inner double quotes break the string boundary
{"message": "He said "hello" to her"}Escape inner double quotes with backslash
{"message": "He said \"hello\" to her"}Extra closing brace
Extra closing brace causes SyntaxError at end of file
{
"status": "ok",
"data": {
"id": 5
}
}}Braces must be perfectly balanced
{
"status": "ok",
"data": {
"id": 5
}
}How to Repair Corrupted JSON (AI-Generated or Log Output)
AI tools like ChatGPT and Claude sometimes produce JSON with subtle errors — especially when asked to generate large JSON structures or when the output is truncated. Common AI-generated JSON problems include:
- Trailing commas on the last element (because models learn from JavaScript code more than strict JSON)
- Truncated output that ends mid-string or mid-array when the response hits a token limit
- Mixed quoting styles when the prompt included examples in different styles
- Missing closing brackets when nested structures are deep
Log aggregation tools like Splunk, Datadog, and CloudWatch also produce stringified JSON — where a JSON object is encoded as a string inside another JSON object. This creates double-escaped strings that need to be unescaped before they can be parsed.
// What you see in the log:
const raw = '{"level":"info","message":"{\"user\":\"alice\",\"action\":\"login\"}"}';
// Step 1: parse outer JSON
const outer = JSON.parse(raw);
// { level: 'info', message: '{"user":"alice","action":"login"}' }
// Step 2: parse the inner stringified JSON
const inner = JSON.parse(outer.message);
// { user: 'alice', action: 'login' }
console.log(inner.user); // 'alice'Auto-repair with the JSON Fixer