A JSON error message often points at the place where the parser gave up, not the place where the mistake began. The fastest fix is to classify the failure before changing the document.
Start by confirming that the input is complete and is actually JSON. Then separate strict-syntax issues from JSONC or JSON5, transport failures, encoding problems, and schema mismatches. This prevents random edits that hide the original cause.
Unexpected token near a comma or bracket
A trailing comma before } or ] is valid in some JavaScript contexts but invalid in strict JSON. Remove it, then inspect the previous property for a missing value. An unexpected closing bracket can also mean an earlier object or array was closed in the wrong order.
Single quotes and unquoted keys
JavaScript object literals and JSON5 can use syntax that JSON.parse rejects. Replace single-quoted strings with properly escaped double-quoted strings and quote every object key. Do not use a global text replacement when apostrophes can appear inside values.
Comments and control characters
Strict JSON does not allow line or block comments. Literal newlines, tabs, and some control characters inside strings must be escaped. If comments are meaningful, keep the source as JSONC and generate a strict JSON artifact for APIs.
HTML or empty responses labeled as JSON
The famous “Unexpected token <” error often means a server returned an HTML login or error page. An unexpected end error can mean an empty or truncated response. Check status, Content-Type, redirects, body length, and network failures before editing the payload.
Valid syntax but wrong data
If parsing succeeds but the application rejects the value, inspect the schema. Strings and numbers are not interchangeable, null differs from a missing property, array items may need one type, and dates are ordinary strings unless the application validates their format.
A repeatable repair sequence
Preserve the raw response, check transport metadata, detect the JSON dialect, format with error positions, repair only known syntax issues, validate the result, and compare repaired output against the source. In production, fix the producer instead of permanently repairing malformed API data downstream.
Summary
Most JSON failures fall into a few groups: wrong dialect, broken delimiters or quotes, invalid string escapes, non-JSON server responses, truncation, or schema mismatch. Diagnose the group first, fix the earliest cause, and preserve the raw input for comparison.