What does a JSON unexpected token error mean?
A JSON parser reads a document from left to right. An “unexpected token” message means the next character or value is not legal at the point where the parser encountered it. The token might be a comma, quote, brace, bracket, letter, or end-of-input marker.
The message is about syntax, not the meaning of your application data. A document can be syntactically valid and still fail a schema or business rule later.
How to read the reported location
Start at the reported line and column, then look one or two tokens backward. The parser often points to where it could no longer continue, while the cause is a missing comma, an extra comma, an unclosed string, or a malformed value just before that point.
- Copy the complete response or file into the JSON Validator.
- Read the line, column, and source context around the diagnostic.
- Inspect the previous delimiter and the value before the highlighted token.
- Make one small correction, then validate again.
Common causes of unexpected token errors
- Trailing commas: remove the comma before a closing brace or bracket.
- Single quotes: use double quotes for strings and property names.
- Unquoted keys: quote keys even when they look like simple identifiers.
- Missing separators: add commas between members and colons between keys and values.
- JavaScript-only values: replace
undefined,NaN, functions, and comments with standard JSON values or remove them. - HTML or text instead of JSON: inspect the response status and content type when an API returns an error page.
- Truncated input: check whether a response ended before its closing braces, brackets, or quote.
A practical fix workflow
- Preserve a copy of the original input so the change is reversible.
- Validate the full document instead of checking only a selected line.
- Fix structural delimiters first: braces, brackets, commas, and colons.
- Fix string quoting and escape sequences next.
- Remove comments and JavaScript-only values if the consumer expects strict JSON.
- Validate again, then use the JSON Formatter to inspect nesting and indentation.
When the source comes from an API, also check whether the response is actually JSON. A proxy, authentication page, or server error may return HTML while your client still attempts to parse it as JSON.
Examples and corrections
Trailing comma
{
"name": "Orbilyra",
"active": true,
}Corrected JSON
{
"name": "Orbilyra",
"active": true
}The comma after true promises another object member, but the object closes immediately. Removing it fixes the syntax.
JavaScript-like syntax
{ 'name': "Orbilyra" }Strict JSON form
{ "name": "Orbilyra" }Single quotes are valid in some JavaScript expressions, but standard JSON requires double-quoted strings.
Unexpected end of JSON input
This message usually means that the parser reached the end while waiting for a closing delimiter, a value, or the rest of a string. Compare the response length with the expected payload and check whether a stream, proxy, or file operation cut the content short.
For a quick check, format the smallest complete object or array you can isolate. If that succeeds, progressively add the remaining fields until the truncated or malformed section is identified.
Validate after the fix
Use the JSON Validator to confirm syntax, then review the result with the JSON Formatter. The validator does not check application schemas, required fields, or business rules; those checks belong to the consuming application or a JSON Schema validator.
All Orbilyra JSON tool input is processed locally in your browser. Do not paste secrets into any online service unless you understand its data handling and trust the destination.