DevKit Tools

Why Is My JSON Invalid? The Six Errors Behind Almost All of Them

3 min read3 October 2026By Muhammad Abdullah

A JSON parse error is frustrating precisely because the text usually looks fine. The reason is that most broken JSON is valid JavaScript: it was written by someone thinking in object literals, or pasted out of code, a log, or a config file. JSON is a much stricter subset, and six specific differences account for nearly every failure.

Try it as you readJSON FormatterFormat, minify, validate and sort JSON in your browser. Errors point to the exact problem. Nothing is uploaded.

1. A trailing comma

JavaScript forgives a comma after the last item in an object or array. JSON does not. This is the most common error by a wide margin, usually left behind after deleting the last line of a list.

js
{ "name": "DevKit", "tools": 166, }   // invalid: trailing comma
{ "name": "DevKit", "tools": 166 }    // valid

2. Single quotes

JSON strings and keys must use double quotes. Single quotes are fine in JavaScript and in Python's dictionary repr, which is exactly where most single-quoted JSON comes from.

js
{ 'name': 'DevKit' }    // invalid: single quotes
{ "name": "DevKit" }    // valid

3. Unquoted keys

In a JavaScript object literal a key can be a bare identifier. In JSON every key is a quoted string, with no exceptions.

js
{ name: "DevKit" }      // invalid: bare key
{ "name": "DevKit" }    // valid

4. Comments

JSON has no comment syntax at all. Neither // nor /* */ is allowed. This catches people out with configuration files, because several tools accept a commented variant and quietly let you get used to it.

js
{
  "port": 3000  // invalid: comments are not JSON
}

5. Values JSON does not have

JSON has exactly six kinds of value: string, number, boolean, null, object and array. Several things that look like values in other languages are not among them.

  • undefined, NaN and Infinity from JavaScript are not valid. Use null instead.
  • Python's True, False and None must be lowercase true, false and null.
  • Functions, dates as objects and regular expressions cannot be represented directly; dates are usually sent as ISO strings.

6. A raw newline inside a string

A string value cannot contain a literal line break or tab character. They must be escaped as \n and \t. This tends to appear when multi-line text is pasted straight into a value by hand.

How to find the error quickly

Do not hunt by eye. The parser already knows where it failed. A strict parser reports a position, often as a line and column or a character offset, and the mistake is almost always at that point or just before it. A trailing comma, for instance, is reported at the closing brace that follows it, because that is where the parser realised something was wrong.

Paste the text into a formatter that surfaces the parser's own message rather than a generic "invalid JSON". The position tells you where to look, and the list above tells you what you are probably looking at.

Fix it by hand, or repair it?

For one or two errors, fixing by hand is fastest and you learn the pattern. For a large payload with many small problems, a JavaScript object pasted wholesale, or a truncated log, an automated repair that scans character by character will close brackets, drop trailing commas and convert quotes in one pass. Read what it changed before trusting it, especially if it had to guess how to close a truncated structure.

Common questions

What does 'Unexpected token' mean in a JSON error?

The parser hit a character it did not expect at that position. It is usually a trailing comma, a single quote, an unquoted key or a comment right at or before the reported spot.

Can JSON have comments?

No. Standard JSON has no comment syntax. Some tools accept a looser variant called JSONC, but a strict parser will reject comments.

Is JSON the same as a JavaScript object?

No. JSON is a stricter text format. Every JSON document is valid JavaScript, but plenty of JavaScript object literals are not valid JSON.

Tools from this guide

More guides