JSON Error Analyzer
Don't just see "Unexpected token" — understand exactly what's wrong and how to fix it. Get detailed explanations, visual highlighting, and auto-fix suggestions.
Click "Analyze Errors" to get detailed information about any JSON issues.
Common JSON Errors Quick Reference
{"a": 1,}→{"a": 1}{'a': 1}→{"a": 1}{a: 1}→{"a": 1}{"a": 1 "b": 2}→{"a": 1, "b": 2}{"a": undefined}→{"a": null}{"a": "line1\nline2"}→{"a": "line1\\nline2"}Why "Unexpected Token" Isn't Helpful
We've all seen it: SyntaxError: Unexpected token at position 142. But what does that actually mean? This tool goes beyond the cryptic error message to tell you:
- Exactly where the error is (line and column)
- What character is causing the problem
- Why it's wrong in plain English
- How to fix it with specific suggestions
- Auto-fix for common issues
Common JSON Errors Explained
Trailing Commas
JavaScript allows trailing commas, but JSON doesn't:
// Wrong - trailing comma after "active"
{
"name": "John",
"active": true, ← Remove this comma
}
// Correct
{
"name": "John",
"active": true
}Why: JSON was designed to be a strict subset of JavaScript with unambiguous parsing rules. Trailing commas were excluded to keep the format simple.
Single Quotes Instead of Double Quotes
JSON requires double quotes for all strings:
// Wrong - single quotes
{'name': 'John'}
// Correct - double quotes
{"name": "John"}Why: The JSON specification mandates double quotes. This prevents ambiguity and ensures consistent parsing across all platforms.
Unquoted Property Names
JavaScript lets you write {name: "John"}, but JSON doesn't:
// Wrong - unquoted key
{name: "John"}
// Correct - quoted key
{"name": "John"}Why: Requiring quotes ensures that keys can contain any valid string, including spaces and special characters.
Missing Commas Between Elements
Easy to miss when editing JSON by hand:
// Wrong - missing comma
{
"name": "John" ← Missing comma here
"age": 30
}
// Correct
{
"name": "John",
"age": 30
}Invalid Values
Some JavaScript values aren't valid in JSON:
// Wrong - undefined isn't valid JSON
{"value": undefined}
// Wrong - NaN and Infinity aren't valid
{"value": NaN}
{"value": Infinity}
// Correct - use null or strings
{"value": null}
{"value": "NaN"}
{"value": "Infinity"}Control Characters in Strings
Raw tabs, newlines, and other control characters must be escaped:
// Wrong - literal newline in string
{"text": "line 1
line 2"}
// Correct - escaped newline
{"text": "line 1\nline 2"}Understanding Error Positions
When JSON parsers report an error "at position 142", they're counting from the start of the string. This tool converts that to line and column numbers, which are much easier to find in your editor.
Important: The error position is usually where the parserdetected the problem, not necessarily where the actual mistake is. For example, a missing comma might not be detected until the parser hits the next property name.
Tips for Debugging JSON
- Start with valid JSON — Use the JSON Repair tool to auto-fix common issues before debugging manually.
- Check the line above — Often the real error is on the linebefore where it's reported (like a missing comma).
- Look for copy-paste issues — JSON from JavaScript code often has single quotes or trailing commas that need fixing.
- Validate incrementally — If you have a large JSON file, try validating smaller sections to isolate the problem.
- Use syntax highlighting — A good editor will show mismatched brackets and unclosed strings visually.
Error Messages by Browser
Different JavaScript engines report JSON errors differently:
| Browser | Example Error Message |
|---|---|
| Chrome/Node | Unexpected token , at position 42 |
| Firefox | JSON.parse: expected property name at line 3 column 5 |
| Safari | JSON Parse error: Expected '}' |
This tool normalizes these messages into a consistent, helpful format.
Programmatic Error Handling
// JavaScript - wrapping JSON.parse for better errors
function parseJSONWithDetails(text) {
try {
return { success: true, data: JSON.parse(text) };
} catch (e) {
const posMatch = e.message.match(/position (\d+)/);
if (posMatch) {
const pos = parseInt(posMatch[1], 10);
const lines = text.substring(0, pos).split('\n');
return {
success: false,
error: e.message,
line: lines.length,
column: lines[lines.length - 1].length + 1,
context: text.substring(pos - 20, pos + 20)
};
}
return { success: false, error: e.message };
}
}Related Tools
- JSON Validator — Quick validation with error highlighting
- JSON Repair — Automatically fix common issues
- JSONC to JSON — Strip comments from config files
- JSON Pretty Print — Format JSON for readability
Frequently Asked Questions
Why does the error say line 1 when my JSON is 100 lines?
This usually happens with minified JSON (no newlines). The entire content is technically on "line 1". The column number and position will help you find the actual location.
The error position seems wrong. Why?
JSON parsers report where they detected an error, not where the mistake actually is. For example, if you forget a comma, the parser won't know until it sees the next unexpected token.
Can this fix all JSON errors?
Auto-fix works for common structural issues (trailing commas, single quotes, unquoted keys). For more complex problems, use the JSON Repair tool or fix manually using the suggestions provided.
Common Mistakes & Pro Tips
- Tabs and BOM shift the column number — Reported columns count characters, so a tab is one column even though your editor renders it as several spaces — the visual position won't match. A UTF-8 byte-order mark (BOM) at the start of the file also counts as a character and pushes everything right by one, which is a common source of confusing column offsets.
- The error points at the symptom, not always the cause — JSON parsers report where parsing failed, which is often after the real mistake. A missing comma is frequently flagged at the start of the next key, and an unterminated string is flagged at the line's end or the next quote, so look just before the reported position.
- Line and column are 1-based here — This analyzer reports the first line and column as 1, matching most editors. Note that the raw JavaScript JSON.parse error gives a character position (0-based offset) instead, so don't be surprised if a stack-trace number differs by one from what you see here.
- Trailing commas are the most common single error — A comma after the last element of an array or object ([1, 2,]) is valid in JavaScript but illegal in JSON, and it's the top cause of parse failures. The analyzer flags the exact comma so you can delete it rather than hunting through the whole document.
Frequently Asked Questions
What does "Unexpected token in JSON" actually mean?
It means the parser reached a character it couldn't fit into the grammar at that point — often a stray comma, a single quote, an unquoted key, or text that isn't valid JSON at all. The analyzer translates this into a plain-English explanation and points to the line and column so you can see exactly what tripped it up.
How do I find which line has the error in a large file?
Paste the full document and the analyzer reports the exact line and column of the first parse failure. Because parsers stop at the first error, fix that one, then re-run to surface the next — large files often contain several issues that only reveal themselves one at a time.
Why does the column number not match my editor?
Columns are counted in characters, not visual width. Tabs count as a single column even though they look like several spaces, a leading BOM adds one, and multi-byte Unicode characters are each one column. Switch your editor to show character position rather than visual column to line them up.
The parser says my JSON is invalid but it looks fine — why?
Usually it's an invisible or look-alike character: a smart/curly quote pasted from a document instead of a straight ", a non-breaking space, or a trailing comma you skimmed past. The analyzer pinpoints the position so you can replace the offending character with the plain ASCII equivalent.
Does it explain how to fix the error, not just where it is?
Yes. Alongside the line and column, it gives a short plain-English description of the likely cause and the fix — for example, "remove the trailing comma" or "this key needs double quotes." The goal is to make the error self-explanatory instead of cryptic.
Is the JSON I paste sent to a server for analysis?
No. The analysis uses your browser's own JSON parser and runs locally, so your data never leaves the page. That makes it safe to paste API responses, tokens, or other sensitive content while debugging.