Common JSON Parsing Errors — Interview Questions
Reviewed by Gurusankar M.
Short Answer
The usual culprits: trailing commas, single quotes or unquoted keys, comments, unescaped control characters or quotes inside strings, wrong encoding/BOM, and truncated payloads ('Unexpected end of input'). A frequent one is calling JSON.parse on something that isn't JSON at all — like an HTML error page ('Unexpected token < in JSON').
On this page
Concept Made Simple
Coffee Chat Question
“What are common JSON parsing errors and their causes?”
Remember It Faster
Mind Map Answer
- Unexpected token <
- parsing an HTML/error page as JSON
- Trailing comma
- comma after last item
- Unexpected end
- truncated / empty body
- Bad quotes
- single quotes / unescaped chars
Learn by Doing
Hands-on Keyboard
JSON.parse("{'a':1}"); // ❌ single quotes -> SyntaxError
JSON.parse('{"a":1,}'); // ❌ trailing comma
JSON.parse(''); // ❌ Unexpected end of input
JSON.parse('<html>...'); // ❌ Unexpected token < (got HTML)
JSON.parse('{"a":1}'); // ✅ okThink Beyond the Expected
What If?
Your API call fails with 'Unexpected token < in JSON at position 0' — what happened?
You tried to JSON.parse an HTML page, not JSON. Usually the request hit a proxy/error page or a 404/500 that returned HTML, and the client parsed the body blindly. Fix it by checking the HTTP status and Content-Type before parsing, and by logging the raw response body.
Real World
'Unexpected token < in JSON' is one of the most-Googled front-end errors — it almost always means the endpoint returned an HTML error page. Checking status/content-type before parsing prevents it.
Interviewer's Expectation
Keywords they're listening for:
- trailing comma / single quotes
- unescaped chars
- truncated body
- wrong content (HTML)
- check status/content-type first
Common Mistakes
- Parsing before checking HTTP status/content-type
- Assuming a 200 always means valid JSON
- Not logging the raw body on failure
Best Practices
- Verify status + Content-Type before parsing
- Wrap parsing in try/catch
- Log the raw response when parsing fails
Follow-up Questions
- How do you handle these errors gracefully?
- Why check Content-Type before parsing?
- How does encoding/BOM cause parse failures?
Continue Learning with AI
Take this question deeper with your favourite AI assistant. Pick a depth, copy the prompt, or open it directly — AI is your learning companion, not a shortcut.
Plain-language foundations
I'm preparing for a software engineering interview and want to understand this from scratch, as a beginner. Topic: Parsing (JSON) Interview question: "What are common JSON parsing errors and their causes?" Please: 1. Explain the core idea in simple, plain language, using an everyday analogy. 2. Define any technical terms you use. 3. Walk through one small, concrete example. 4. Finish with a single sentence I can easily remember. Keep the tone friendly and assume I'm new to this topic.
Was this answer helpful?
Affiliate links
Tools for Your Developer Workspace
Equipment for a comfortable, productive setup.
As an Amazon Associate I earn from qualifying purchases.
- MonitorView on Amazon : BenQ EW2790U 27-inch Monitor (opens in a new tab)
BenQ EW2790U 27-inch Monitor
- LaptopView on Amazon : Acer Aspire One Laptop (opens in a new tab)
Acer Aspire One Laptop
- Office ChairView on Amazon : Wakefit Gravita Ergonomic Office Chair (opens in a new tab)
Wakefit Gravita Ergonomic Office Chair