The rules of valid JSON in 30 seconds
- Keys and strings use double quotes only.
- Values can be a string, number, object, array,
true,falseornull. Nothing else. - Items are separated by commas, with no comma after the last item.
- No comments of any kind.
- Special characters inside strings must be escaped with a backslash.
The fastest way to find a problem is to paste your data into our free JSON Formatter & Validator. It points to the exact line and column of the first error, and it runs in your browser so private data stays on your device.
1. Trailing commas
{ "name": "Ayesha", "age": 29, }
JavaScript tolerates the comma after the last item; JSON does not. Parsers report something like Unexpected token } or Expected double-quoted property name. Fix: delete the final comma in every object and array.
2. Single quotes
{ 'name': 'Ayesha' }
Fix: use double quotes for every key and string: { "name": "Ayesha" }.
3. Keys without quotes
{ name: "Ayesha" }
Valid in a JavaScript object, invalid in JSON. Fix: quote every key.
4. Comments
{
"port": 8080 // default port
}
Standard JSON has no comments. Some tools accept a relaxed variant (often called JSONC or JSON5), but a strict parser will fail. Fix: remove the comment, or store the note as data, for example "_comment": "default port".
5. Missing commas between items
[ "red" "green", "blue" ]
Often caused by copying lines together. Fix: add the missing comma. If the validator points to the start of a line, the problem is usually at the end of the line above.
6. Unescaped characters inside strings
{ "path": "C:\Users\ayesha", "quote": "She said "hi"" }
Backslashes and double quotes inside a string must be escaped, and real line breaks are not allowed inside a string. Fix:
{ "path": "C:\\Users\\ayesha", "quote": "She said \"hi\"", "lines": "first\nsecond" }
7. Values that do not exist in JSON
undefined, NaN, Infinity, dates such as new Date(), functions and numbers with leading zeros (007) or a plus sign (+5) are all invalid. Fix: use null for missing values, write numbers plainly (7, 5) and store dates as strings, for example "2026-11-09T10:30:00Z".
8. Unclosed or mismatched brackets
{ "items": [ 1, 2, 3 }
Each { needs a matching } and each [ a matching ], closed in the right order. Fix: format the data with indentation; a missing bracket becomes obvious when the nesting looks wrong.
9. Smart quotes and invisible characters
JSON pasted from Word, Google Docs or a chat app may contain curly quotes such as “ and ” instead of straight ", non-breaking spaces or a hidden byte-order mark at the start of a file. The data looks right but will not parse. Fix: retype the quotes in a code editor, and save files as UTF-8 without BOM.
10. It is not JSON at all
Unexpected token < in JSON at position 0
This classic message means the response starts with <, usually an HTML error page (404, 500 or a login page) instead of the JSON you expected. Fix: open the request in your browser’s network tab, check the status code and the response body, and fix the URL, authentication or server error first.
How to avoid JSON errors in the first place
- Do not build JSON by hand in code. Use
JSON.stringify()in JavaScript,json.dumps()in Python or your language’s equivalent; they always produce valid output. - Validate before you ship. Run config files through a validator or a linter in your editor and in your build pipeline.
- Use a schema (JSON Schema) for important files and API payloads, so missing or wrongly typed fields are caught early.
- Check API responses before parsing: confirm the status code and the
Content-Type: application/jsonheader.
Frequently asked questions
Are trailing commas allowed in JSON?
No. Standard JSON does not allow a comma after the last item of an object or array, even though JavaScript does.
Can JSON contain comments?
Not in standard JSON. Formats such as JSONC (used by some editors’ settings files) and JSON5 allow them, but strict parsers and most APIs will reject them.
What does “position 0” in an error mean?
The parser failed at the very first character, which usually means the input is empty or is not JSON at all, such as an HTML page.
Are duplicate keys an error?
Most parsers accept them but keep only the last value, which can hide bugs. Treat duplicate keys as a mistake and remove them.
