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.
In this guide
- The rules in one minute
- 1. Trailing commas
- 2. Single quotes
- 3. Unquoted keys
- 4. Comments
- 5. Values that do not exist in JSON
- 6. Number formatting
- 7. Unescaped characters in strings
- 8. Missing commas and colons
- 9. Unbalanced brackets and extra data
- 10. Invisible and copied characters
- How to read the error message
- Frequently asked questions
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,falseandnull. There is noundefined,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",],
}{
"name": "Asha",
"roles": ["admin", "beta"]
}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}{"name": "Asha", "active": true}3. Unquoted keys
{ name: "Asha", age: 30 }{ "name": "Asha", "age": 30 }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
}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"}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 as | Valid? | Write it as |
|---|---|---|
+5 | No | 5 |
007 | No | 7 (or the string "007" if the zeros matter) |
.5 | No | 0.5 |
5. | No | 5.0 or 5 |
0x1F | No | 31 |
1.5e3 | Yes | Exponents 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"}{"message": "She said \"hello\""}
{"path": "C:\\Users\\asha"}
{"text": "line one\nline two"}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"
}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:
| Where | Message | Usually means |
|---|---|---|
| Browsers and Node.js | Unexpected token } in JSON at position 25, or Expected double-quoted property name | A trailing comma, or a stray character, just before position 25 |
| Browsers and Node.js | Unexpected end of JSON input | The text is empty or cut off; a closing bracket or quote is missing |
| Python | Expecting property name enclosed in double quotes: line 1 column 9 | Single quotes, an unquoted key or a trailing comma |
| Python | Expecting ',' delimiter | A missing comma between two items |
| Python | Extra data | More 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.