Common JSON Mistakes and Fixes
Most JSON errors come from developers who know JavaScript well but mix up its object literal syntax with JSON's stricter rules. The fixes are always simple — once you know what to look for.
Mistake 1: Trailing comma
The most common JSON error. A comma after the last item in an object or array is valid in JavaScript and Python, but not in JSON.
Invalid:
{
"name": "Alice",
"age": 30,
}Fixed:
{
"name": "Alice",
"age": 30
}The same rule applies inside arrays: [1, 2, 3,] is invalid — remove the last comma.
Mistake 2: Single quotes
JSON requires double quotes for both keys and string values. Single quotes are valid in JavaScript object literals but not in JSON.
Invalid:
{'name': 'Alice', 'city': 'London'}Fixed:
{"name": "Alice", "city": "London"}Mistake 3: Unquoted keys
JavaScript allows {name: "Alice"} but JSON does not. Every key must be a quoted string.
Invalid:
{name: "Alice", age: 30}Fixed:
{"name": "Alice", "age": 30}Mistake 4: undefined or NaN values
undefined, NaN, and Infinity exist in JavaScript but are not valid JSON values. Serializing them with JSON.stringify() silently drops them or converts them to null.
Invalid:
{"result": undefined, "ratio": NaN}Fixed (use null or omit the field):
{"result": null}Mistake 5: Comments
JSON has no comment syntax. Not //, not /* */, not #. This is one of the most frequent frustrations for developers coming from YAML or JavaScript.
Invalid:
{
"port": 3000,
// Default port for development
"host": "localhost"
}Fixed — remove the comment:
{
"port": 3000,
"host": "localhost"
}If you need comments, consider JSONC (supported by VS Code) or store metadata in a dedicated _comment key.
Mistake 6: Number stored as string (or vice versa)
Wrapping a number in quotes makes it a string. This matters when your code does arithmetic or strict comparisons.
{"count": "42"}This is valid JSON but count is a string. If your API expects a number, it will likely fail. Use the correct type:
{"count": 42}Mistake 7: Duplicate keys
JSON parsers handle duplicate keys inconsistently — some keep the first, some keep the last. Never use duplicate keys.
{
"status": "active",
"status": "inactive"
}How to find mistakes fast
- Paste into a validator — it points to the exact line and character
- Check the error message: "Unexpected token ," usually means trailing comma; "Unexpected token '" means single quotes
Try it in JSON Prism
The JSON Debugger goes beyond syntax checking — it shows you exactly what went wrong and suggests fixes. For pure syntax validation with line-precise error reporting, use the JSON Validator.