JSON Parse Error: “Unexpected Token” — How to Fix It
A JSON parse error usually reads something like “Unexpected token } in JSON at position 42” or “Unexpected end of JSON input”. The message is terse, but it points at a specific character — and in practice only a handful of mistakes cause it.
This guide explains what the error means and how to locate the exact problem quickly.
What “unexpected token” means
A JSON parser walks the document character by character and expects a strict structure. When it meets a character that cannot legally appear where it is, it throws “Unexpected token”. The fix is almost always to delete or correct that character.
The four usual causes
- Trailing comma: a comma before a closing } or ] — for example { "a": 1, }.
- Single quotes: keys and strings must use double quotes, not single quotes.
- Comments: // or /* */ are not valid JSON and must be removed.
- Unquoted keys: { key: 1 } is invalid; it must be { "key": 1 }.
“Unexpected end of JSON input”
This one means the document stopped too early — a missing closing brace or bracket, or a truncated payload. Count your braces, or paste it into a validator that balances them for you.
How to find the exact spot
Paste the JSON into the formatter on this site. Instead of a generic failure it reports the parse error at the exact position so you can jump straight to it. Formatting a valid document also makes mismatched braces obvious.
Try it yourself — free and private
These tools run entirely in your browser. Nothing is uploaded.
JSON Formatter
Format, validate and beautify JSON in your browser — no upload.
Base64 Encoder / Decoder
Encode text to Base64 or decode it back — UTF-8 safe, no upload.
Properties to YAML Converter
Convert Java .properties to YAML (and back) — Spring Boot friendly, no upload.
Frequently Asked Questions
What does “unexpected token in JSON at position 0” mean?
Position 0 is the very first character, so the response is usually HTML rather than JSON — for example an error page or a login redirect returned instead of the API payload you expected.
Is it safe to paste my JSON into an online formatter?
Only if it processes the data locally. The formatter on this site runs entirely in your browser, so tokens, keys and payloads are never sent to a server.
Can a JSON validator fix the error for me?
A validator cannot guess your intent, but it pinpoints the offending character, so the fix is usually a one-second edit — typically removing a trailing comma or swapping quotes.