Open huge JSON files instantly. Free & private.๐Ÿ”’ Your data never leaves your browser

9 Common JSON Syntax Errors and How to Fix Them

JSON looks like JavaScript, but it is much stricter. Most "invalid JSON" errors come from a short list of mistakes, usually from writing JSON by hand, copying it from code, or receiving it from a system that does not follow the standard. Here are the nine most common, each with a broken and a fixed example.

Try it: JSON RepairFix most of these mistakes automatically in one click.
Open JSON Repair โ†’

1. Trailing commas

A comma after the last item in an object or array is not allowed.

โœ—  { "name": "Ann", "age": 30, }
โœ—  [1, 2, 3,]
โœ“  { "name": "Ann", "age": 30 }
โœ“  [1, 2, 3]

2. Single quotes

Both keys and string values must use double quotes. Single quotes and backticks are not valid.

โœ—  { 'city': 'Cairo' }
โœ“  { "city": "Cairo" }

3. Unquoted keys

In JavaScript you can write keys without quotes. In JSON every key is a string in double quotes.

โœ—  { id: 7, active: true }
โœ“  { "id": 7, "active": true }

4. Comments

JSON has no comments. //, /* */ and # all cause errors. (Some tools, like VS Code settings, accept a variant called JSONC that allows comments, but standard parsers do not.)

โœ—  {
     // server port
     "port": 8080
   }
โœ“  { "port": 8080 }

If you need to document a value, add a regular field such as "_comment": "server port", or use a format that supports comments, like YAML.

5. Missing commas

Easy to miss when you add a line to a multi-line object:

โœ—  {
     "a": 1
     "b": 2
   }
โœ“  {
     "a": 1,
     "b": 2
   }

The error is reported on the line after the missing comma, at "b", because that is where the parser realizes something is wrong.

6. Special values: NaN, Infinity, undefined

JSON supports only strings, numbers, true, false, null, objects and arrays. NaN, Infinity and undefined are not valid. Python's True, False and None are not valid either.

โœ—  { "score": NaN, "ok": True, "note": None }
โœ“  { "score": null, "ok": true, "note": null }
๐Ÿ’ก Python's json.dumps() writes NaN by default, which other languages then reject. Pass allow_nan=False to catch this early, and convert such values to None yourself.

7. Line breaks and tabs inside strings

A string cannot contain a raw line break or tab. They must be escaped:

โœ—  { "text": "line one
line two" }
โœ“  { "text": "line one\nline two" }

The same goes for a double quote inside a string: write \". Backslashes in Windows paths must be doubled: "C:\\Users\\ann".

8. Invalid numbers

JSON numbers cannot have leading zeros, a leading plus sign, a leading or trailing dot, or hexadecimal notation.

โœ—  { "a": 007, "b": +3, "c": .5, "d": 5., "e": 0xFF }
โœ“  { "a": 7,   "b": 3,  "c": 0.5, "d": 5,  "e": 255 }

If a value like a zip code or a phone number needs its leading zeros, store it as a string: "zip": "01234".

9. Extra content around the JSON

The text must contain exactly one JSON value. These all fail:

  • A JavaScript assignment: const data = { ... };
  • A JSONP wrapper: callback({ ... })
  • Markdown code fences copied from a chat or documentation (three backticks)
  • Several objects one after another, like in log files. That format is called JSON Lines (NDJSON) and has to be read line by line, or wrapped in an array.
  • An invisible byte-order mark (BOM) at the very start of a file saved by some Windows editors

How to find and fix errors fast

  1. Paste the text into the JSON Validator. It shows the exact line and column and explains the problem in plain English.
  2. If there are many problems, run it through JSON Repair. It fixes all nine mistakes above and lists every change it made. Long numbers keep all their digits.
  3. Prevent errors at the source: generate JSON with JSON.stringify() or json.dumps() instead of building strings by hand.

Seeing a specific error message? See Unexpected token in JSON for what each message means.

Tools used in this guide

More guides