JSON Syntax Errors: The 8 Mistakes and How to Fix Them
6 min read · Published October 14, 2026 · Updated October 14, 2026
You paste a response into your code, run it, and the parser answers with something like "Unexpected token } in JSON at position 87." The message points at a character, but the real mistake is often a few characters earlier, and staring at a wall of minified text does not help.
JSON is a small format with strict rules, and almost every error comes from a short list of habits carried over from JavaScript, Python, or hand-edited config files. This guide covers what valid JSON requires, the eight mistakes that cause most failures, and a workflow for finding the problem quickly.
What valid JSON actually requires
JSON has only a handful of building blocks. A value is one of: an object, an array, a string, a number, true, false, or null. Objects are wrapped in curly braces and hold key-value pairs separated by commas. Arrays are wrapped in square brackets and hold values separated by commas. Strings use double quotes only.
Two rules catch most people. Every key in an object must be a double-quoted string, and there is no way to leave a comma after the last item. Beyond that, whitespace between tokens is ignored, which is why a formatted document and a minified one are the same data.
Numbers are also stricter than in many languages. They cannot start with a plus sign, cannot have leading zeros such as 007, and cannot be NaN or Infinity. Dates have no special type, so they travel as strings, usually in ISO 8601 form like 2026-10-14.
{
"name": "Ada",
"active": true,
"scores": [91, 84.5, 78],
"manager": null
}Mistakes 1 to 4: punctuation habits
The first group comes from writing JSON the way you would write a JavaScript object literal. They are easy to make and easy to fix once you know the pattern.
- Trailing comma. A comma after the last item in an object or array is invalid. Before: {"a": 1, "b": 2,} After: {"a": 1, "b": 2}
- Single quotes. Strings and keys must use double quotes. Before: {'city': 'Oslo'} After: {"city": "Oslo"}
- Unquoted keys. Before: {city: "Oslo"} After: {"city": "Oslo"}
- Comments. JSON has no comment syntax, so // note and /* note */ both fail. Remove them, or store the note as a real field such as "_comment": "note" if the consuming program tolerates unknown keys.
Mistakes 5 to 8: values and structure
The second group is subtler because the text often looks fine at a glance. These tend to appear when data is copied from logs, printed with a language's default formatting, or assembled by string concatenation.
- Missing comma between items. Before: {"a": 1 "b": 2} After: {"a": 1, "b": 2}
- Wrong literals. Python prints True, False, and None, and JavaScript has undefined. JSON wants true, false, and null in lowercase. Before: {"ok": True, "id": None} After: {"ok": true, "id": null}
- Unescaped characters inside strings. A raw line break or an unescaped double quote ends or breaks the string. Use \n for a newline and \" for a quote. Before: {"msg": "She said "hi""} After: {"msg": "She said \"hi\""}
- Mismatched or extra brackets. Every opening brace or bracket needs a partner of the same kind, in the right order. Before: {"list": [1, 2, 3}} After: {"list": [1, 2, 3]}
Also invalid: {"n": 007} {"n": +5} {"n": NaN}
Valid: {"n": 7} {"n": 5} {"n": null}Formatting versus minifying
Formatting, sometimes called pretty-printing, adds line breaks and indentation so a person can read the structure. Minifying removes every optional space and line break so the text is as small as possible. Neither changes the data: a parser produces identical results from both.
Use formatted JSON when you are reading, reviewing a diff, or editing by hand, since indentation makes mismatched brackets visible. Use minified JSON when size matters, for example in a network payload or a value stored in a single field. A common pattern is to keep readable files in source control and minify only at the point where the text is sent or stored.
One caution: formatting does not fix errors. A formatter has to parse the text first, so invalid JSON usually produces an error message instead of tidy output. That failure is useful, because it tells you validation is the first step.
A debugging workflow that saves time
When a parser rejects your text, work through the same short sequence every time rather than scanning randomly.
First, validate the whole document and read the reported position. Treat it as a pointer to look just before, since the parser notices a problem only when it meets a character that cannot be valid, such as a closing brace right after a trailing comma. Second, fix one error and validate again, because a single missing quote can cause a cascade of later complaints that disappear together. Third, if the text came from somewhere else, check how it was produced. Output from a language's print function is not JSON; use that language's proper serializer instead.
If the document is large, bisect it. Remove half of the array items, validate, and see whether the error persists. Within a few rounds you will have isolated the offending record.
- Check for smart quotes. Text pasted from word processors or chat apps may contain curly quotes that look right but are not the ASCII double quote.
- Check the start of the file. A hidden byte order mark or stray text before the first brace can fail the whole parse.
- Check for several JSON documents joined together. Two objects one after another are not one valid document.
Checking JSON without sending it anywhere
JSON often contains customer records, API responses, or configuration values you would rather not upload to a stranger's server. The ELDOSA JSON Formatter and Validator parses what you paste inside your browser and shows indented output or an error message, and the separate JSON Validator gives a quick valid-or-not answer. Both run locally, so the text is not transmitted for processing.
Even so, it is good practice to remove secrets such as API keys, passwords, and tokens before pasting data into any tool. Replacing a value with a placeholder rarely changes whether the structure is valid, which is usually the question you are trying to answer.
Tools mentioned in this guide
Frequently asked questions
Why does JSON not allow comments?
The format was designed to be minimal and unambiguous for data exchange, so comments were left out. If you need annotations in a configuration file, look for a superset format your tooling supports, or keep notes in a separate document or in an ordinary field.
Is an empty object or an empty string valid JSON?
An empty object written as {} is valid, and so is an empty array written as []. A completely empty string is not valid JSON, because a document must contain exactly one value. That is why empty responses sometimes cause a parse error.
Can a JSON document be just a number or a string?
Yes. Current specifications allow any value at the top level, so 42, "hello", true, and null are each valid documents. Some older parsers expected an object or array at the top, so check your tooling if you rely on scalar documents.
Does key order matter in a JSON object?
The specification treats objects as unordered collections, so programs should not depend on order. Most parsers preserve the order they read, but if two systems must agree on a precise order, define it outside the JSON itself, or use an array.