Guides

Invalid JSON: 7 Common Errors and How to Fix Them

If your JSON throws an error when you load it, it's almost always one of seven things: a trailing comma, single quotes, unquoted keys, comments, unescaped characters, values JSON doesn't recognize, or curly quotes pasted from a document. Here's how to spot each one and fix it in seconds, without uploading your data to any server.

The tool for this guide

JSON formatter and validator

It runs inside your browser: nothing you enter leaves this page.

Open JSON formatter and validator

Quick summary

Symptom Likely cause Fix
Fails right before a } or ] Trailing comma after the last item Delete that comma
Fails at the first character of a key Single quotes or unquoted key Always use double quotes
Fails on a line starting with // Comments Remove them
Fails in the middle of a string Unescaped quote, backslash or line break Write them as \", \\ or \n
Fails on a value undefined, NaN, True, None, 007 Replace with null, true or a quoted string
Everything looks fine but it still fails Smart quotes or invisible characters Retype the quotes by hand
Fails at position 0 with < It's not JSON, it's an HTML page Check where the response comes from

The fastest way to find the error

  1. Copy your entire JSON, from the first brace to the last.
  2. Paste it into the JSON formatter and validator.
  3. If it's valid, you'll see it neatly indented. If not, the validator tells you there's an error.
  4. Go to the spot of the error and compare it with the causes below.

One detail that trips a lot of people up: when a message says at position 57, it counts characters starting from zero, including spaces and line breaks. And the mistake is usually right before that position, not at it: the JSON parser keeps reading until it hits something it didn't expect.

The 7 most common causes

1. Trailing comma after the last item

This is the number one error. It happens when you delete the last line of a list and leave the previous line's comma behind.

  • Bad: {"name": "Ana", "age": 30,}
  • Good: {"name": "Ana", "age": 30}

The same goes for arrays: [1, 2, 3,] is not valid. JavaScript and other languages accept that trailing comma, which is why your code works and your JSON doesn't. Typical messages: Expected double-quoted property name or Unexpected token }.

2. Single quotes instead of double quotes

JSON only accepts double quotes, for both keys and strings.

  • Bad: {'name': 'Ana'}
  • Good: {"name": "Ana"}

This happens a lot when someone prints a Python dictionary and pastes it as if it were JSON: {'active': True} has single quotes and a value JSON doesn't recognize. If you generate JSON from Python, use json.dumps() instead of converting the dictionary to a string directly.

3. Unquoted keys

In a JavaScript object you can write {name: "Ana"}. In JSON you can't: every key goes in double quotes.

  • Bad: {name: "Ana", age: 30}
  • Good: {"name": "Ana", "age": 30}

If you copied the object from a code file, check every key, not just the first one.

4. Comments

JSON doesn't support comments. Not // like this and not /* like this */.

You have two options:

  • Delete them, if they were notes to yourself.
  • Turn them into a field, if the note has to travel with the data: "_note": "price excludes tax".

Some config files use a JSON variant that does allow comments, which is why it sometimes seems like you can. But if you're going to read the file with a standard JSON parser, it will fail.

5. Unescaped characters inside a string

Inside a quoted string, some characters can't be typed as-is. You write them with a backslash in front:

What you want to type How to write it inside the string
Double quote " \"
Backslash \ \\
Line break \n
Tab \t

The two cases that fail most often:

  • Quotes inside the string. "message": "He said "hello"" ends the string too early. Correct: "message": "He said \"hello\"".
  • Windows file paths. "path": "C:\Users\ana\data.json" fails because \U, \a and \d aren't valid escapes. Correct: "path": "C:\\Users\\ana\\data.json", or use forward slashes: "C:/Users/ana/data.json".

If you pasted multi-line text straight between quotes, you'll see something like Bad control character in string literal: replace each line break with \n.

6. Values that don't exist in JSON

JSON only understands a handful of value types: strings in double quotes, numbers, true, false, null, objects {} and arrays []. Anything else breaks the file:

  • undefined, NaN and Infinity (from JavaScript): replace them with null.
  • True, False and None (from Python) or TRUE: write them as true, false and null, all lowercase.
  • Numbers with a leading zero like 007, a plus sign like +5, starting with a decimal point like .5, or in hexadecimal like 0x1F.
  • Unquoted dates like 2024-05-10: they go in as strings, "2024-05-10".

Watch out for leading zeros: a ZIP code like 01000 shouldn't be a number. Even if you "fixed" it by dropping the zero, you'd lose data. Store it as a string: "zip": "01000". The same goes for phone numbers, order numbers and product codes.

7. Smart quotes and invisible characters

This is the most maddening one, because at a glance the JSON looks perfect. If you copied the text from a word processor, a chat or an email, the straight quotes " may have turned into curly quotes “ like this ”. To JSON they're different characters, and they don't count as quotes.

Non-breaking spaces or invisible characters can also sneak in at the start of the file. You can't see them, but they make parsing fail.

How to fix it:

  • Search for “ and ” and replace them with ".
  • If the error points to a spot where you see nothing odd, delete that stretch and retype it by hand.
  • Avoid building or editing JSON in word processors; use a plain text editor.

If it's none of these

  • Unclosed braces or brackets. The message Unexpected end of JSON input almost always means the JSON is incomplete: a } or ] is missing, or the file got cut off (a partial copy, an interrupted download, a truncated response). Formatting it with indentation makes it easier to see which block was left open.
  • Several objects pasted together. {"id": 1}{"id": 2} is not valid JSON. Wrap them in an array and separate them with commas: [{"id": 1}, {"id": 2}].
  • It's not JSON, it's HTML. Unexpected token < in JSON at position 0 means what you received starts with <: almost always an error page (404, 500) or a login screen. The problem is in the request, not in the JSON.
  • Empty file. A file or response with no content isn't valid JSON either.

If you have an earlier version that worked, compare it with the one that fails using Compare two texts to see exactly what changed.

Why you should validate it without uploading it

JSON is rarely harmless: it often contains API keys, tokens, customer emails, addresses or internal settings. Pasting it into a validator that sends it to a server means handing that data over to someone else.

Utiliobox's JSON formatter and validator runs in your browser: your JSON is processed on your device and isn't uploaded anywhere. You can paste your real API response there without scrubbing the data first.

Validate your JSON now

Paste your JSON into the JSON formatter and validator, find the error and fix it using the list above. It's free, there's nothing to install, and your data never leaves your device.

The tool for this guide

JSON formatter and validator

It runs inside your browser: nothing you enter leaves this page.

Open JSON formatter and validator

More guides