Skip to content
Developer GuideJSON & Data

How to Fix JSON Unexpected Token Errors

Understand JSON unexpected token errors, locate the real syntax mistake, and fix trailing commas, quotes, separators, and truncated input with practical examples.

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.

  1. Copy the complete response or file into the JSON Validator.
  2. Read the line, column, and source context around the diagnostic.
  3. Inspect the previous delimiter and the value before the highlighted token.
  4. 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

  1. Preserve a copy of the original input so the change is reversible.
  2. Validate the full document instead of checking only a selected line.
  3. Fix structural delimiters first: braces, brackets, commas, and colons.
  4. Fix string quoting and escape sequences next.
  5. Remove comments and JavaScript-only values if the consumer expects strict JSON.
  6. 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.

FAQ

Frequently asked questions

What does an unexpected token error mean in JSON?

It means the parser found a character or value that cannot appear at that position in standard JSON. The reported location is where parsing stopped, so the actual mistake can be immediately before it.

Why does JSON reject a trailing comma?

Standard JSON requires another member or item after a comma. A comma before a closing brace or bracket is therefore invalid, even though some JavaScript syntax accepts it.

Why are single quotes invalid in JSON?

JSON strings and object keys must use double quotes. Single-quoted strings belong to JavaScript-like syntax, not the standard JSON grammar.

What is unexpected end of JSON input?

The parser reached the end before finding a required closing brace, bracket, string character, or value. Check for truncated responses and unclosed structures.

Does a JSON parser error identify the exact original mistake?

Not always. Parsers report the first point where the remaining text became impossible to interpret, so inspect the token and the separator or value immediately before it.

Can comments appear in JSON?

No. Standard JSON has no comment syntax. JSONC and other extensions may support comments, but they require a parser that explicitly supports that dialect.

Is valid JSON the same as valid application data?

No. Syntax parsing only confirms that the text is JSON. Required fields, types, ranges, and business rules need JSON Schema or application validation.

Does Orbilyra send my JSON to a server?

No. The JSON Validator and Formatter process input locally in your browser. The guide itself contains no upload or server-processing step.

← Back to Developer Guides