JSON Syntax & Debugging Guide: Fixing the 8 Most Common Parse Errors
Strict RFC 8259 JSON is far less forgiving than JavaScript object literals. A single stray comma, unquoted property name, or server HTML error page will crash JSON.parse() immediately. Here are the eight bugs developers hit most often—and how to spot them in seconds.
The 8 Most Common JSON Parse Errors
Unexpected token < at position 0: Almost always means your API endpoint returned an HTML<!DOCTYPE html>404, 502, or login redirect page instead of JSON. Checkresponse.statusandContent-Typebefore callingresponse.json().- Trailing commas:
{"a": 1, "b": 2,}is valid JavaScript but illegal JSON. Remove the comma after the last item in every object and array. - Single quotes: JSON strictly requires double quotes (
"name") around both keys and string values—never single quotes ('name'). - Unquoted keys:
{ status: "ok" }fails; write{ "status": "ok" }. - Comments inside
.jsonfiles: Standard JSON forbids//and/* */comments (use JSONC only in editors that explicitly support it, like VS Codetsconfig.json). - Raw unescaped newlines inside strings: Multi-line string values must escape line breaks as
\nand internal double quotes as\". undefined,NaN, orInfinityvalues: None of these exist in JSON—serialize missing values asnull.- Invisible UTF-8 BOM (
\uFEFF): Files exported from older Windows tools sometimes prepend an invisible Byte Order Mark at index 0; strip it before parsing.
2. Debugging API JSON Failures Step by Step in Production
When a frontend React, Vue, or mobile app crashes with SyntaxError: Unexpected end of JSON input or Unexpected token <, chasing the bug blindly in minified production logs wastes hours. Follow this 4-step triage sequence instead:
- Inspect the Raw HTTP Status &
Content-TypeFirst: Never callawait response.json()blindly. Checkif (!response.ok)and logawait response.text()first—you will immediately see whether Nginx returned a502 Bad GatewayHTML page or an empty204 No Contentresponse. - Pretty-Print With Line Numbers: Minified 50 KB API payloads hide missing brackets at column 42,109. Paste the raw payload into our local JSON Formatter & Validator to pinpoint the exact failing line and character offset.
- Watch Out for Double-Encoded JSON Strings: If your parsed result is a
stringstarting with"{\"id\":1}"instead of an object, the backend calledJSON.stringify()twice. Fix the upstream serializer rather than double-parsing in the client. - Generate Strict TypeScript Contracts: Once your payload is valid, paste it into our JSON to TypeScript Interface Generator so future schema drifts trigger compile-time errors instead of silent runtime crashes.
3. Frequently Asked Questions About JSON Syntax
Why doesn't standard JSON allow comments like JavaScript or YAML?
JSON's creator Douglas Crockford intentionally omitted comments from RFC 8259 so parsers could remain tiny, fast, and immune to people embedding non-standard parsing directives inside comments. If you need commented config files, use JSONC (VS Code) or YAML/TOML.
Why do 64-bit integer IDs (like Snowflake IDs) lose precision in JavaScript JSON?
JavaScript represents all numbers as IEEE 754 double-precision floats, which only preserve exact integers up to 2^53 - 1 (9,007,199,254,740,991). APIs returning 64-bit numeric IDs should serialize them as quoted JSON strings ("id": "1844674407370955161") to prevent silent last-digit rounding.
Is it safe to paste staging API payloads into Findteck's JSON Formatter?
Yes. Our JSON Formatter executes strictly inside your browser's native JavaScript engine with zero backend requests—meaning tokens, user objects, and internal configs never leave your laptop.
Comments (0)
Leave A CommentNo comments yet.
Be the first to share your thoughts, questions, or review of this guide!