Common JSON Parsing Errors β Interview Questions
β‘ 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').
βCoffee Chat Question
Concept Made Simple
βWhat are common JSON parsing errors and their causes?β
π§ Mind Map Answer
Remember It Faster
β¨οΈHands-on Keyboard
Learn by Doing
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}'); // β
okπ₯What If?
Think Beyond the Expected
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:
β οΈ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
- 1How do you handle these errors gracefully?
- 2Why check Content-Type before parsing?
- 3How does encoding/BOM cause parse failures?
π§©Related Technologies
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?
β Featured Products
Support our platform by exploring our recommended products.
As an Amazon affiliate, purchases through these links may earn us a small commission β at no extra cost to you. It helps keep Full Stack Interview Guru free.