Common JSON Errors and How to Fix Them
JSON has very strict rules, and a single stray character makes a whole document invalid. The good news is that almost every broken JSON file fails for one of the same eight reasons. Learn to recognize them and you'll fix most errors in seconds.
Most of these mistakes come from the same place: JSON looks almost exactly like a JavaScript or Python object, and both of those languages are more forgiving. Code that works fine as a JavaScript object literal can still be invalid JSON. For each mistake below you'll see a broken example, the fixed version, and a link that opens the broken one in the JSON tool so you can watch the error marker appear and practice the fix.
1. Trailing commas
A trailing comma is a comma after the last item in an object or array. JavaScript, Python and most modern languages allow it, so it's easy to leave one behind after deleting a line or copying data out of code. JSON does not allow it.
{
"name": "Ada Lovelace",
"languages": ["English", "French"],
"active": true,
}{
"name": "Ada Lovelace",
"languages": ["English", "French"],
"active": true
}The error usually points at the closing } or ], not at the comma itself, because the parser only realizes something is wrong when it finds a bracket where it expected another key or value. Chrome and Node report it as Expected double-quoted property name inside objects and Unexpected token ']' inside arrays.
Open the “Trailing comma” example in the JSON tool
2. Missing commas
Every item in an object or array must be separated from the next by a comma. This one usually happens when you add a new line to the end of an object and forget to put a comma on the line before it.
{
"id": 1024,
"title": "Learn JSON"
"done": false
}{
"id": 1024,
"title": "Learn JSON",
"done": false
}The error is often on the line above
Parsers report the position where they noticed the problem, which is the start of "done" on line 4. The comma is actually missing from the end of line 3. When an error points at the very start of a line that looks fine, check the end of the line before it.
Open the “Missing comma” example in the JSON tool
3. Single quotes
JSON strings, including keys, must use double quotes ("). Single quotes (') are valid in JavaScript and Python, but not in JSON. You'll often see this when someone prints a Python dictionary and pastes the output, since Python displays dictionaries with single quotes.
{
'city': 'Lisbon',
'country': 'Portugal'
}{
"city": "Lisbon",
"country": "Portugal"
}If your JSON came from Python, don't fix it by hand: convert the data with json.dumps() instead of print() or str(). The Python JSON guide shows how.
Open the “Single quotes” example in the JSON tool
4. Keys without quotes
In a JavaScript object you can write { name: "Grace" }. In JSON, every key must be a string in double quotes, even simple one-word keys.
{
name: "Grace Hopper",
born: 1906
}{
"name": "Grace Hopper",
"born": 1906
}This mistake is common when copying an object out of JavaScript source code. If you have the object in a running program, JSON.stringify(yourObject, null, 2) produces valid JSON with every key quoted.
Open the “Unquoted keys” example in the JSON tool
5. Comments
Standard JSON has no comments at all: not // line comments, not /* block comments */ and not # hash comments. Douglas Crockford, who popularized JSON, left them out deliberately so that JSON would stay a pure data format.
{
// Port the dev server listens on
"port": 3000,
"debug": true
}{
"port": 3000,
"debug": true
}Some tools do accept comments in their own config files. VS Code's settings.json and TypeScript's tsconfig.json use a variant often called "JSON with Comments" (JSONC). That's why a file can work in one tool and fail in a strict parser like JSON.parse(). If you need to explain a value in plain JSON, add a normal key such as "_comment": "Port the dev server listens on" instead.
Open the “Comments” example in the JSON tool
6. Values JSON doesn't allow
JSON supports exactly six kinds of value: strings, numbers, objects, arrays, true/false, and null. Several values that look reasonable are not on that list:
undefined,NaNandInfinityfrom JavaScriptTrue,FalseandNonefrom Python. JSON's literals are lowercase:true,false,null- Numbers written with a leading zero (
007), a plus sign (+1), in hexadecimal (0x1F), or with a trailing dot (5.) - Dates as bare values. Write them as strings, for example
"2026-12-05"
{
"score": NaN,
"nickname": undefined,
"verified": True
}{
"score": null,
"nickname": null,
"verified": true
}If a value is missing or unknown, use null, or leave the key out entirely. If a number with leading zeros matters, like a ZIP code ("02134") or a phone number, store it as a string: it's an identifier, not a quantity.
Open the “Values JSON doesn't allow” example in the JSON tool
7. Unescaped quotes, backslashes and line breaks
Inside a JSON string, a few characters have special meaning. A double quote ends the string, and a backslash starts an escape sequence. To include them as ordinary text, put a backslash in front: \" and \\. Real line breaks and tabs aren't allowed inside a string at all; write them as \n and \t.
{
"path": "C:\Users\ada\notes.txt",
"quote": "She said "hello""
}{
"path": "C:\\Users\\ada\\notes.txt",
"quote": "She said \"hello\""
}Windows file paths are the classic trap: \U isn't a valid escape sequence, so the parser stops with an error like Bad escaped character. Worse, \n in \notes.txt is valid and silently turns into a line break. The escaping guide covers every escape sequence.
Open the “Unescaped characters” example in the JSON tool
8. Missing or extra brackets
Every { needs a matching } and every [ needs a matching ], closed in the reverse order they were opened. Missing a closing bracket is common when JSON gets cut off: a log line that was truncated, a copy that didn't select everything, or a download that stopped early.
{
"user": {
"name": "Linus",
"roles": ["admin", "dev"]
}{
"user": {
"name": "Linus",
"roles": ["admin", "dev"]
}
}When a closing bracket is missing, the error points at the very end of the text, with a message like Unexpected end of JSON input or Expected ',' or '}'. An extra bracket produces Unexpected non-whitespace character after JSON (Chrome and Node) or Extra data (Python). Indentation is your best friend here: in a prettified document each closing bracket lines up with the line that opened it, so a missing one stands out.
Open the “Missing bracket” example in the JSON tool
How to find the error quickly
- Get a line and column. Paste the JSON into the tool. It marks the first error on its exact line, with a short explanation and a link back to the matching section of this guide. In code, Chrome, Node and Python all include a position in their error messages.
- Look just before the marker. The parser reports where it gave up, which is often one token after the real mistake: the comma missing from the previous line, or the quote that wasn't closed earlier on the same line.
- Fix one error at a time. A parser stops at the first problem, so fixing it may reveal the next one further down. That's normal progress, not a new problem.
- Prettify long one-line JSON. An error at "column 4,817" of a single line is hard to find. Once the JSON is valid, Prettify spreads it over many lines; until then, look at the characters around the reported column.
- Check you have JSON at all. If the error is on line 1, column 1, the text probably isn't JSON. It might be an HTML error page, an empty response, or a Python dictionary. See what JSON error messages mean.
How to avoid these errors in the first place
The most reliable way to get valid JSON is not to write it by hand. Let your language produce it: JSON.stringify() in JavaScript, json.dumps() in Python, or the equivalent in your language. These functions always add the right quotes, commas and escapes. When you do edit JSON by hand, such as a config file or a test fixture, use an editor that checks JSON as you type, and paste the result into a validator before you commit it.