JSON Debugging
JSON Unexpected Token Debugging Guide
Debug JSON unexpected-token errors by inspecting response metadata, parser offsets, encoding, escaping and truncated payload evidence. This reference is written for developers who need practical validation behavior, reviewable rules and safe examples rather than copied snippets with no explanation.
Recommended workflow
| Step | Why it matters |
|---|---|
| Inspect the raw response | Confirm the payload is JSON rather than an HTML error page, login redirect or proxy message. |
| Check metadata | Record HTTP status, Content-Type, Content-Encoding and byte length before parsing. |
| Locate the token | Use line, column or character offset and inspect a small redacted window around it. |
| Trace the producer | Fix invalid escaping, truncation or mixed output where it originates. |
Starter snippet
content-type -> raw bytes -> status code -> parser line and column -> surrounding tokenReview checks
- Handle empty success responses explicitly.
- Decode compression before text parsing.
- Redact tokens before sharing payload samples.
- Test non-ASCII input and byte-order marks.
Common mistakes
- Logging the full production payload.
- Assuming token less-than always means a frontend bug.
- Catching the parse error and continuing with partial data.
Validation should help users correct input while protecting systems from bad data. Keep syntax checks, product policy, security review and deliverability checks separate.
Related Formalint references
Continue with JSON Lint Error, API Error Response Design, Network Tab Debugging Guide.