Common JSON Errors and How to Fix Them (With Examples)
JSON looks simple, but one misplaced comma or quote is enough to break an API request, a config file or a data import. Error messages such as “Unexpected token” or “Expecting property name enclosed in double quotes” rarely tell you what went wrong in plain words.
This guide lists the most common JSON syntax errors, shows the broken and fixed version of each, and explains how to find problems fast with the free AurexToolz JSON Validator, which validates, formats and minifies JSON in your browser.
Quick JSON Syntax Rules
Most errors come from breaking one of these rules from the JSON standard (RFC 8259):
- Data is written as objects
{ }and arrays[ ]. - Object keys must be strings in double quotes.
- String values must use double quotes, not single quotes.
- Items are separated by commas, with no comma after the last item.
- Allowed values are strings, numbers, objects, arrays,
true,falseandnull. - Comments are not allowed.
1. Trailing Commas
A comma after the last item in an object or array is valid in JavaScript code but not in JSON.
// Invalid
{
"name": "Aurex",
"active": true,
}
// Valid
{
"name": "Aurex",
"active": true
}
2. Single Quotes Instead of Double Quotes
// Invalid
{ 'city': 'Lahore' }
// Valid
{ "city": "Lahore" }
In Python this often shows up as Expecting property name enclosed in double quotes. A common cause is printing a Python dictionary with str() instead of converting it with json.dumps().
3. Unquoted Keys
// Invalid
{ id: 101, status: "paid" }
// Valid
{ "id": 101, "status": "paid" }
4. Missing Commas Between Items
// Invalid
{
"first": "Ali"
"last": "Khan"
}
// Valid
{
"first": "Ali",
"last": "Khan"
}
5. Unclosed or Mismatched Brackets
Every { needs a matching } and every [ needs a matching ]. In long files, formatting the JSON with consistent indentation makes a missing bracket easy to spot.
// Invalid
{ "items": [1, 2, 3 }
// Valid
{ "items": [1, 2, 3] }
6. Comments Inside JSON
JSON has no comment syntax, so // or /* */ lines cause a parse error. Remove them, or store notes in a regular field such as "_note" if your application allows it.
// Invalid
{
// API version
"version": 2
}
// Valid
{
"version": 2
}
7. Invalid Values: undefined, NaN, Infinity
JavaScript values such as undefined, NaN and Infinity are not valid JSON. Use null or a string instead. Booleans and null must also be lowercase: True or NULL will fail.
// Invalid
{ "discount": undefined, "ratio": NaN, "verified": True }
// Valid
{ "discount": null, "ratio": null, "verified": true }
8. Unescaped Characters in Strings
Double quotes, backslashes and line breaks inside a string must be escaped. Windows file paths are a frequent culprit.
// Invalid
{ "path": "C:\Users\data", "quote": "He said "hi"" }
// Valid
{ "path": "C:\\Users\\data", "quote": "He said \"hi\"" }
9. Numbers with Leading Zeros or Wrong Format
JSON numbers cannot have leading zeros (such as 007), a leading plus sign, or a trailing decimal point. If a value like a postal code or phone number must keep its leading zeros, store it as a string.
// Invalid
{ "code": 007, "price": 12. }
// Valid
{ "code": "007", "price": 12.0 }
10. Not Actually JSON (HTML or Empty Response)
An error like Unexpected token < at position 0 usually means the response is HTML, often an error page or login redirect, rather than JSON. An “Unexpected end of JSON input” error often means the response was empty or cut off. Check the HTTP status code and the raw response before parsing.
Common Error Messages and What They Mean
| Error message (example) | Likely cause |
|---|---|
| SyntaxError: Unexpected token } in JSON | Trailing comma or missing value before a closing bracket |
| Expected double-quoted property name | Unquoted key, single-quoted key, or trailing comma |
| Unexpected token < in JSON at position 0 | Server returned HTML instead of JSON |
| Unexpected end of JSON input | Empty response or missing closing bracket |
| JSONDecodeError: Expecting property name enclosed in double quotes (Python) | Single quotes or trailing comma in an object |
| JSONDecodeError: Expecting value (Python) | Empty string, invalid value, or non-JSON response |
The exact wording varies between browsers and languages; see the MDN reference for JSON.parse() for JavaScript behaviour.
How to Find and Fix JSON Errors Fast
- Paste your JSON into the JSON Validator and click Run.
- Read the error message and go to the reported line or position. The real mistake is often just before that point, such as a missing comma on the previous line.
- Fix one error at a time and validate again; a single missing quote can trigger several follow-on errors.
- Once the JSON is valid, format it for readability or minify it to reduce size before sending it in an API request or saving it to a file.
If you are cleaning up markup at the same time, the HTML and CSS formatter can beautify or minify front-end code in the same way.
Best Practices to Prevent JSON Errors
- Generate JSON with code, not by hand. Use
JSON.stringify()in JavaScript orjson.dumps()in Python so quoting and escaping are handled for you. - Validate before you deploy. Check config files and API payloads with a validator or a linter in your editor.
- Use a schema for important data. JSON Schema lets you check required fields and data types, not just syntax.
- Save files as UTF-8. JSON text exchanged between systems should be UTF-8 encoded.
- Check responses before parsing. Confirm the HTTP status and
Content-Type: application/jsonheader before calling a JSON parser.
Conclusion
Most JSON errors come down to a handful of causes: trailing or missing commas, the wrong quotes, unquoted keys, comments, invalid values and unescaped characters. Learn to recognise them, generate JSON with code where you can, and run anything handwritten through the JSON Validator before it reaches production. The official overview at json.org is a handy reference for the full syntax.
Frequently Asked Questions
Why is my JSON invalid?
The most common reasons are a trailing comma after the last item, single quotes instead of double quotes, unquoted keys, missing commas between items, comments, or unescaped quotes and backslashes inside strings.
Are trailing commas allowed in JSON?
No. The JSON standard does not allow a comma after the last item in an object or array, even though JavaScript code does.
Can JSON contain comments?
No. Standard JSON has no comment syntax. Remove comments before parsing or use a separate field for notes if your application supports it.
What does “Unexpected token < in JSON at position 0” mean?
It usually means the server returned HTML, such as an error or login page, instead of JSON. Check the request URL, authentication and HTTP status code.
How do I validate JSON online?
Paste it into an online JSON validator such as the AurexToolz JSON Validator and run it. The tool reports syntax errors and can format or minify valid JSON.

