Common JSON Errors and How to Fix Them

Troubleshooting 9 min readUpdated October 12, 2026

JSON looks like a JavaScript object, which is exactly why so many people write it wrong. The format is strict and small: a handful of rules that every parser enforces. Once you know the ten mistakes below, you can fix almost any "Unexpected token" error in under a minute.

The rules in one minute

JSON is defined in RFC 8259. The rules that cause nearly all problems are these:

  • Strings and object keys must use double quotes. Single quotes are not allowed.
  • There are no comments of any kind.
  • There is no trailing comma after the last item of an object or array.
  • The only values are objects, arrays, strings, numbers, true, false and null. There is no undefined, NaN, Infinity, date type or function.
  • Numbers cannot have a leading plus sign, leading zeros (other than a single 0), or a bare decimal point.
  • A document is one value. Two objects side by side are not valid JSON.

1. Trailing commas

The most common error by far, usually left behind after deleting or reordering the last item.

{
  "name": "Asha",
  "roles": ["admin", "beta",],
}
Invalid: two trailing commas
{
  "name": "Asha",
  "roles": ["admin", "beta"]
}
Fixed

2. Single quotes

Python dictionaries and JavaScript objects accept single quotes, but JSON does not. This often happens when someone prints a Python dictionary with print(data) and pastes the output.

{'name': 'Asha', 'active': True}
Not JSON: single quotes, and Python's capitalised True
{"name": "Asha", "active": true}
Fixed. In Python, generate JSON with json.dumps(data) instead of print(data)

3. Unquoted keys

{ name: "Asha", age: 30 }
Valid JavaScript, invalid JSON
{ "name": "Asha", "age": 30 }
Fixed: every key is a double-quoted string

4. Comments

Standard JSON has no comment syntax. Neither // nor /* */ is allowed. Some tools accept them as an extension (VS Code's settings files use a variant called JSONC, and TypeScript's tsconfig.json allows comments), but a strict parser will reject them.

{
  // number of retries
  "retries": 3
}
Invalid in strict JSON

If you need to annotate data, add a field such as "_comment": "number of retries", or keep the explanation in documentation. If a file is meant to contain comments, name it for what it is (JSONC or JSON5) and parse it with a parser that supports it.

5. Values that do not exist in JSON

undefined, NaN, Infinity and -Infinity are JavaScript values with no JSON equivalent. JSON.stringify quietly drops properties whose value is undefined, and turns NaN and Infinity into null, so the failure often only shows up later.

JSON.stringify({ a: undefined, b: NaN, c: Infinity, d: new Date(0) });
// {"b":null,"c":null,"d":"1970-01-01T00:00:00.000Z"}
a disappeared, b and c became null, and the date became a string

Decide how missing and unknown values should be represented, usually null or an omitted key, and use strings for dates (ISO 8601 is the convention).

6. Number formatting

Written asValid?Write it as
+5No5
007No7 (or the string "007" if the zeros matter)
.5No0.5
5.No5.0 or 5
0x1FNo31
1.5e3YesExponents are allowed

Values like postal codes, phone numbers and account numbers with leading zeros should be strings, because a number cannot preserve them.

7. Unescaped characters in strings

Inside a string, a double quote, a backslash and any control character (including a real line break or tab) must be escaped.

{"message": "She said "hello""}
{"path": "C:\Users\asha"}
{"text": "line one
line two"}
Three invalid strings: raw quotes, an invalid escape sequence, and a real newline
{"message": "She said \"hello\""}
{"path": "C:\\Users\\asha"}
{"text": "line one\nline two"}
Fixed: \" for a quote, \\ for a backslash, \n for a newline

The valid escapes are \", \\, \/, \b, \f, \n, \r, \t and \uXXXX. Anything else after a backslash, including \', is an error.

8. Missing commas and colons

{
  "id": 1
  "name": "Asha"
}
A comma is missing after 1

Parsers usually report the position of the token after the missing comma, so look at the line before the one in the error message.

9. Unbalanced brackets and extra data

Every { needs a } and every [ needs a ], in the right order. Truncated downloads and copy-and-paste mistakes often cut off the closing brackets. A related error appears when there is more than one value in the text, for example two objects one after another, or a log file with one JSON object per line (often called JSON Lines or NDJSON). A normal parser reads the first value and then complains about the rest. Parse such files line by line.

10. Invisible and copied characters

  • Smart quotes. Text copied from a word processor, a chat window or a web page can contain curly quotes, which look right but are different characters.
  • Byte order mark (BOM). Some Windows editors add an invisible marker at the start of a UTF-8 file. RFC 8259 says generators must not add one, and some parsers fail on it.
  • Non-breaking spaces. These look like spaces but are not valid whitespace in JSON.

If the text looks perfect but still fails, retype the suspicious punctuation, or save the file as UTF-8 without BOM.

How to read the error message

Parsers describe where they gave up, which is usually right after the real mistake. Typical messages:

WhereMessageUsually means
Browsers and Node.jsUnexpected token } in JSON at position 25, or Expected double-quoted property nameA trailing comma, or a stray character, just before position 25
Browsers and Node.jsUnexpected end of JSON inputThe text is empty or cut off; a closing bracket or quote is missing
PythonExpecting property name enclosed in double quotes: line 1 column 9Single quotes, an unquoted key or a trailing comma
PythonExpecting ',' delimiterA missing comma between two items
PythonExtra dataMore than one JSON value in the text

A validator that highlights the exact line and column is faster than counting characters by hand. Paste the text, find the marker, then check the line above it as well.

Frequently asked questions

Why is my JSON valid in JavaScript but invalid in a parser?

JavaScript object literals are more relaxed than JSON. They allow single quotes, unquoted keys, trailing commas and comments. A JSON parser accepts none of these.

Can JSON have duplicate keys?

The grammar allows them, but RFC 8259 says names should be unique and that behaviour with duplicates is unpredictable. Most parsers keep the last value and ignore earlier ones. Avoid duplicates, and validate for them if the data comes from outside your control.

Is an empty string valid JSON?

No. An empty document is not a value, so parsers report an error such as "Unexpected end of JSON input". The shortest valid documents are values like null, 0, "", {} and [].

How can I stop producing invalid JSON in the first place?

Never build JSON by joining strings. Create a data structure and let a serializer write it, such as JSON.stringify, Python's json.dumps or your framework's JSON support. Serializers handle quoting and escaping for you.

Related guides

See all 12 guides

© 2026 TrueJson. All rights reserved.