JSON looks simple enough that it is easy to assume it is hard to get wrong. Then you paste a config file into your app and get back a wall of red text, or an API call fails with a message about an unexpected token at some position number that means nothing to you at a glance. JSON is stricter than it looks, and a handful of the same mistakes account for the overwhelming majority of broken JSON out there.
None of these errors require deep technical knowledge to fix once you recognize the pattern. Below are the ten that show up most often, what the actual error message tends to look like, and exactly how to fix each one.
1. Trailing Comma
Leaving a comma after the last item in an object or array is completely normal in JavaScript, and that habit slips into JSON constantly.
{
"name": "Alex",
"role": "admin",
}
A parser will typically report something like
Unexpected token } in JSON, pointing to the closing brace right after the comma. JSON has no concept of a trailing comma being optional or ignorable, unlike JavaScript. The fix is simple: remove the comma after the final item.
{
"name": "Alex",
"role": "admin"
}
2. Missing Comma
The opposite problem is just as common, forgetting a comma between two fields that need one.
{
"name": "Alex"
"role": "admin"
}
This typically throws an error like
Unexpected string in JSON, since the parser expected either a comma or a closing brace after
"Alex" and got another key instead. Every field except the last one in an object, and every item except the last one in an array, needs a comma immediately after it.
{
"name": "Alex",
"role": "admin"
}
3. Single Quotes Instead of Double Quotes
JavaScript treats single and double quotes as interchangeable. JSON does not.
{’name’: ’Alex’}
This usually fails with something like
Unexpected token ’, since a strict JSON parser only recognizes double quotes as valid string delimiters, for both keys and values. The fix is a straightforward find-and-replace, converting every single quote to a double quote throughout the file.
{"name": "Alex"}
This error is especially common when copying an object literal directly out of JavaScript source code, since single quotes are perfectly normal there and the visual difference between the two quote styles is easy to overlook at a glance.
4. Unquoted Keys
JavaScript allows object keys without quotes as long as they are valid identifiers. JSON requires every key to be a quoted string, no exceptions.
{name: "Alex"}
This tends to throw an error pointing at the key itself, since the parser is expecting a quoted string and instead finds a bare word. JSON keys must always be double-quoted, even when they would technically be valid without quotes in JavaScript.
{"name": "Alex"}
5. Missing or Mismatched Curly Brackets
A missing closing brace does not just break the object it belongs to, it can cause the parser to fail on the entire file, since everything after it gets interpreted as still being inside that unclosed object.
{
"user": {
"name": "Alex"
}
The error here often reads something like
Unexpected end of JSON input, since the parser reached the end of the data while still expecting a closing brace it never found. Counting opening and closing braces carefully, or running the data through a formatter that highlights where the structure breaks down, is the fastest way to spot exactly where one is missing.
This particular error message can be misleading at first, since it points to the very end of the file rather than the actual location of the missing brace. When you see this specific message, it is worth checking the entire structure rather than assuming the problem is near wherever the error appears to point.
{
"user": {
"name": "Alex"
}
}
6. Missing or Mismatched Square Brackets
The same problem shows up with arrays, usually when a closing bracket gets left off or accidentally replaced with the wrong type of bracket.
{
"tags": ["admin", "editor"}
}
Here, the array was closed with a curly brace instead of a square bracket, which produces an error since the parser was expecting
] and got
} instead. Matching each opening bracket type with the correct closing type, square with square, curly with curly, resolves this.
{
"tags": ["admin", "editor"]
}
7. Comments Left in the File
Some configuration formats that resemble JSON allow comments. Standard JSON does not, at all, in any form.
{
// user settings
"theme": "dark"
}
A strict parser will fail immediately on the comment, since
// and
/* */ have no meaning in JSON syntax. The fix is simply removing any comments before treating the file as JSON, or switching to a format that explicitly supports them if comments are genuinely needed.
{
"theme": "dark"
}
8. Unescaped Special Characters in Strings
Certain characters inside a JSON string need to be escaped, most commonly a literal double quote or backslash appearing inside string content.
{"quote": "She said "hello""}
The unescaped quotes inside the string confuse the parser about where the string actually ends, typically producing an error around the unexpected character. Escaping internal quotes with a backslash fixes this.
{"quote": "She said \"hello\""}
9. Using JavaScript-Only Values
JSON supports a specific, limited set of value types: strings, numbers, booleans, arrays, objects, and null. JavaScript object literals allow more than that, and those extras do not survive the conversion to JSON.
{"callback": function() {}, "value": undefined}
Functions and
undefined have no JSON equivalent, and a parser will reject them outright. The fix depends on intent: remove values that genuinely cannot be represented in JSON, or convert them into something JSON actually supports, like a string or null.
{"value": null}
This mistake is especially common when converting a JavaScript object directly into JSON without an actual serializer handling the conversion. A proper serializer either omits unsupported values automatically or converts them sensibly, while a manual copy-paste conversion carries these incompatible values along unchanged.
10. Duplicate Keys
JSON does not explicitly forbid duplicate keys in its specification, but the behavior when they occur is inconsistent, and most parsers simply keep the last occurrence and silently discard the earlier ones.
{"role": "admin", "role": "editor"}
This will not always throw a hard error, which makes it more dangerous than the others on this list, since the data can look valid while quietly losing information. Some validators flag duplicate keys explicitly as a warning, and it is worth removing the redundant one and keeping whichever value is actually correct.
This is exactly the kind of issue that a basic parser will not catch, since the JSON is technically well-formed even with the duplicate. Catching this reliably usually requires either a linter-style tool built specifically to flag it, or a careful manual review, since the data will parse and run without any visible complaint.
{"role": "editor"}
Why JSON Breaks More Often Than You Would Expect
JSON rarely gets written by hand from scratch. It usually arrives from somewhere else, an API response someone copied into a config file, a JavaScript object converted into JSON without checking the syntax rules, a manually edited settings file, or increasingly, output generated by an AI tool that produced something that looks like JSON but is not quite valid.
Each of these sources tends to introduce a different flavor of the errors above. JavaScript-to-JSON conversions bring single quotes, unquoted keys, and trailing commas. Manual edits introduce missing commas and mismatched brackets. Generated or copied content sometimes carries invisible formatting artifacts that are hard to spot just by looking. Knowing where your JSON actually came from is often the fastest way to guess which category of error you are dealing with.
AI-generated content deserves a specific mention here, since it has become an increasingly common source of JSON that looks correct at a glance but fails to parse. Output that resembles JSON closely but includes a stray trailing comma, an inconsistent quote style, or a subtly malformed structure is common enough that treating any generated JSON as unverified until it has been run through a formatter or validator is a reasonable default habit.
How to Fix Broken JSON Quickly
- Run it through a formatter first: Paste the data into ToolMato’s JSON Formatter. If it fails, you already know something is wrong, even before reading the specific error.
- Read the error message carefully: Most parsers report the type of problem and a position, line, or column, which narrows down where to look considerably. Do not skip past this message assuming it is unhelpful, since even a generic-sounding error usually points to roughly the right area.
- Check for the usual suspects first: Trailing commas, missing commas, single quotes, and unquoted keys account for the majority of real-world JSON errors, so scan for these before assuming something more unusual is going on.
- Fix one issue and re-check: JSON errors sometimes cascade, one early mistake can trigger confusing downstream errors. Fixing the first reported issue and re-running the check often reveals a much simpler picture than the original error suggested.
- Validate the final result: Once formatting succeeds, a quick pass through a dedicated validator confirms the fix actually resolved the issue rather than just moving it somewhere else.
Best Practices to Avoid These Errors in the First Place
- Never write JSON by copying a JavaScript object literal without checking quote style, trailing commas, and unquoted keys.
- Use an editor extension that validates JSON in real time, catching errors as you type rather than after the fact.
- Run generated or copied JSON through a formatter before trusting it, especially content from AI tools or scraped sources.
- Keep configuration files formatted and validated in version control, so errors get caught during review rather than at runtime.
- When editing JSON by hand, edit the formatted version rather than a minified one, since spotting a missing comma is dramatically easier with proper indentation.
- If you regularly convert JavaScript objects into JSON, consider automating that conversion with a proper serializer rather than manually retyping the data, since serializers handle quote style and structure correctly by default.
Fixing Errors Elsewhere in Your Stack
JSON is rarely the only thing that breaks. If you are cleaning up a project’s data files, the surrounding JavaScript, HTML, and CSS often need the same attention. ToolMato’s
JavaScript Formatter,
HTML Formatter, and
CSS Formatter help spot similar structural issues across the rest of your codebase.
Frequently Asked Questions
Why is my JSON invalid even though it looks correct?
The most common causes are subtle, a trailing comma, a missing comma, single quotes instead of double quotes, or an unquoted key, all of which are easy to miss at a glance but will cause a strict parser to fail. A careful line-by-line comparison against valid JSON syntax usually reveals the issue quickly.
What does "unexpected token" mean in a JSON error?
It means the parser encountered a character it was not expecting at that point in the data, often because of a missing comma, an extra comma, or a bracket that does not match the surrounding structure.
How do I fix a JSON missing comma error?
Locate the field or array item mentioned near the error position and add a comma immediately after it, as long as it is not the very last item in that object or array.
How do I fix a JSON trailing comma error?
Find the comma sitting right before a closing brace or bracket and remove it. Trailing commas after the final item are invalid in standard JSON.
How do I fix a JSON missing bracket error?
Count the opening and closing brackets in the affected section and add whichever one is missing, matching curly braces with curly braces and square brackets with square brackets.
Why does JSON require double quotes instead of single quotes?
The JSON specification defines double quotes as the only valid string delimiter. This is a strict rule with no exception, unlike JavaScript, which allows both.
Why do my JSON keys need to be quoted?
JSON requires every key to be a string, and strings in JSON must always be wrapped in double quotes, regardless of whether the key would be a valid identifier without them.
How do I repair broken JSON quickly?
Run it through a formatter to see if it fails, read the specific error message, check for trailing commas, missing commas, and quote style first, then fix issues one at a time and re-check until it parses successfully.
Can AI-generated JSON contain formatting errors?
Yes. Content generated by AI tools can sometimes include trailing commas, inconsistent quote styles, or minor structural issues, the same categories of errors that show up in manually written or converted JSON.
Is there a tool that automatically fixes JSON errors?
Some tools attempt automatic repair for common issues like trailing commas or quote style, but they cannot always guess your intent correctly, especially for missing brackets or ambiguous structural problems, so reviewing the result manually is still worthwhile, particularly for data going into production.
Most JSON errors come down to the same small set of causes, and once you can recognize the pattern, fixing them takes seconds instead of the frustrating trial and error that comes from staring at a cryptic parser message. The specific error text varies between tools, but the underlying issue is almost always one of the ten covered here.
Keeping a mental checklist of these common culprits, trailing commas, missing commas, quote style, brackets, turns a confusing parser error into a quick, systematic fix rather than a genuine mystery every time it happens.
Have some broken JSON right now? Paste it into ToolMato’s
JSON Formatter and see exactly where it breaks.