Find the exact problem first
Paste the JSON into the JSON Formatter and Validator. If it is invalid, the error message shows the line and column, prints the problem line and places a pointer under the character where parsing failed. The real mistake is usually at that point or just before it.
The seven most common errors
- Trailing comma.
{"a": 1, "b": 2,}— remove the comma before}or]. - Single quotes.
{'name': 'Ali'}— JSON requires double quotes:{"name": "Ali"}. - Unquoted keys.
{name: "Ali"}is valid JavaScript but not JSON. Quote every key. - Comments.
// noteand/* note */are not allowed in standard JSON. - Missing comma between items:
{"a": 1 "b": 2}. - Unescaped characters in strings. A double quote inside a string must be written
\", a backslash\\, and a line break\n. Windows paths are a frequent cause:"C:\\Users\\Ali". - Invalid values.
undefined,NaN,Infinityand functions are not JSON. Usenullor a string instead.true,falseandnullmust be lower case.
“Unexpected end of JSON input”
This means the parser reached the end before the structure was complete. Common causes are a missing closing } or ], a response that was cut off, or an empty response — for example, an API that returned nothing or an HTML error page instead of JSON. Check the raw response before blaming the parser.
Format, minify and compare
- Format indents the JSON so nested objects are easy to read.
- Minify removes all unnecessary whitespace for sending or storing.
- Sort keys alphabetically to make two documents easier to compare. Then paste both into the Text Diff Checker to see exactly what differs.
Large numbers and relaxed formats
JavaScript can represent integers exactly only up to 9,007,199,254,740,991 (253 − 1). Larger IDs, such as some database or social-media IDs, lose precision when parsed; the tool warns when it detects them. The safe fix is to send such IDs as strings.
Formats such as JSON5 or “JSON with comments”, used by some configuration files, are reported as invalid because they are not standard JSON. That is expected.
Frequently asked questions
Is it safe to paste API responses with private data?
Yes. Formatting and validation run in your browser; nothing is uploaded.
Why does JSON.parse fail on data that looks fine?
Invisible characters, such as a byte-order mark at the start of a file or “smart quotes” copied from a word processor, can break parsing. Retype the quotes or paste the data into a plain-text editor first.