Skip to content
LovTools
EN

Invalid JSON? How to Find and Fix the Error

By Sohail Khax · Published

“Unexpected token” and “Invalid JSON” errors almost always come from a handful of small mistakes. JSON is stricter than JavaScript: what works in code often breaks in a .json file or an API request.

The usual suspects

  • Trailing comma after the last item: {"a": 1,} or [1, 2,]. Remove the final comma.
  • Single quotes: {'name': 'Ada'}. JSON strings and keys need double quotes.
  • Unquoted keys: {name: "Ada"}. Every key must be a string in double quotes.
  • Comments: // … and /* … */ are not allowed in JSON.
  • Special values: undefined, NaN and Infinity are not JSON; use null or a number.
  • Unescaped characters inside strings: a raw line break or a lone backslash. Write \n and \\ instead.

Find the exact spot

  1. Paste the JSON into JSON Formatter.
  2. Press Validate. If something is wrong, you see the line and column — and a hint when the line has a trailing comma or single quotes.
  3. Fix that spot and validate again. Once it is valid, press Beautify to indent it neatly, or Minify to make it as small as possible.
  4. Turn on Sort keys alphabetically to put object keys in alphabetical order — handy for comparing two versions.

Is my data safe?

Yes. The JSON is parsed by your browser’s own engine on your device and never sent anywhere, so API keys or customer data in the file stay private. To turn an array of objects into a spreadsheet, use JSON to CSV.

Tools in this guide

← All posts · How we write and test