Invalid JSON? 8 Common JSON Errors and How to Fix Them

“Unexpected token”, “Expected double-quoted property name”, “Unexpected end of JSON input” – JSON error messages are short and not always helpful. The good news: almost every invalid JSON file comes from the same few mistakes. Here they are, with fixes.

Free tool
Validate and format JSON
Paste JSON to find the exact line and column of an error with a fix hint – then format, minify or sort keys. Free – nothing uploaded.
Open JSON Formatter →

The JSON rules in brief

  • Strings and object keys use double quotes
  • Values: string, number, true, false, null, object {} or array []
  • Items separated by commas – no comma after the last item
  • No comments, no functions, no undefined

1. Trailing comma

{"a": 1, "b": 2,} – the comma before } is not allowed. JavaScript accepts it; JSON does not. Fix: remove the last comma.

2. Single quotes

{'name': 'Priya'} – Fix: use double quotes: {"name": "Priya"}.

3. Keys without quotes

{name: "Priya"} – Fix: {"name": "Priya"}.

4. Missing comma

Two values on separate lines without a comma between them. The error usually points to the start of the second value. Fix: add a comma at the end of the line before.

5. Comments

// note or /* note */ are not allowed. Fix: remove them, or move notes into a field such as "_comment". Some tools accept JSONC or JSON5, but standard JSON parsers do not.

6. undefined, NaN or Infinity

These JavaScript values are not valid JSON. Fix: use null or a real number.

7. Unescaped characters in strings

A double quote, backslash or line break inside a string must be escaped: \", \\, \n. Windows paths are a common trap: "C:\Users" must be "C:\\Users".

8. Empty or truncated response

“Unexpected end of JSON input” usually means the response was empty or cut off. If the error mentions <, you probably received an HTML error page instead of JSON – check the API URL, status code and authentication.

What the error messages mean

Message (Chrome / Node.js)Likely cause
Expected double-quoted property nameTrailing comma, single quotes or unquoted key
Expected ‘,’ or ‘}’ after property valueMissing comma
Unexpected token ‘<‘You received HTML, not JSON
Unexpected end of JSON inputEmpty or truncated data
Bad control character in stringA raw line break or tab inside a string

Our JSON Formatter shows the line, column and a hint for each of these.

Prevent errors in the first place

  • Generate JSON with JSON.stringify or your language’s JSON library, never by joining strings.
  • Validate API responses before parsing in your app.
  • Sort keys and compare versions with the Diff Checker.
  • Converting JSON for Android? See JSON to Kotlin data classes.

FAQ

How do I check if my JSON is valid?

Paste it into a JSON validator. It will confirm it is valid or show where the first error is.

Why is a trailing comma invalid in JSON?

The JSON specification does not allow it, even though JavaScript does.

Can JSON keys use single quotes?

No. Keys and strings must use double quotes.

What does Unexpected token < in JSON mean?

The data starts with <, so it is probably an HTML page, often an error or login page.

Can I add comments to JSON?

Not in standard JSON. Use a separate documentation field or a format like JSONC where supported.

Free tool
Try the free JSON Formatter
No signup and nothing uploaded – it runs right in your browser. Browse all 74 free tools on our Free Tools page.
Open JSON Formatter →

Need a website or app for your business? Talk to Techpass Master – we design and build websites and apps for clients worldwide.

WhatsApp us📞 Call now