Unrecognized token: was expecting a value
Jackson lists the seven things a JSON value can be, because it found something that was none of them: a bare run of letters. The token it quotes back at you is the exact text it could not classify, which usually makes the cause obvious.
How the message appears
Jackson wording. The class is com.fasterxml.jackson.core.JsonParseException on Jackson 2.x, and Spring Boot normally wraps it in an HttpMessageNotReadableException before it reaches your logs.
What causes it
An unquoted string value
Values that look like keywords get written without quotes constantly — ok, yes, active, N/A. JSON has no bare words apart from true, false and null, so every one of them has to be quoted.
undefined, from a JavaScript producer
JavaScript has undefined and JSON does not. A serialiser that writes it out produces a document that no strict parser will read — the fix belongs on the producing side, where undefined should become null or be omitted.
The body is not JSON at all
A plain-text error such as error: upstream timeout reports Unrecognized token 'error'. Check the status code and content type before parsing, rather than trying to fix the document.
A truncated keyword
Unrecognized token 'nul' means the document was cut off mid-word — a truncated response or a buffer written short, not a typo.
The fix
Put double quotes around the value. If the token Jackson quotes back is undefined, fix the producer rather than the document — JSON has no such value, and null or an absent key is what was meant.
{
"id": 7,
"status": ok
}{
"id": 7,
"status": "ok"
}The example travels in the URL fragment, which browsers never send to a server.
Worth knowing
- Jackson can be told to accept some of this —
JsonReadFeature.ALLOW_UNQUOTED_FIELD_NAMES,ALLOW_SINGLE_QUOTES,ALLOW_TRAILING_COMMA. Enabling them makes your service accept documents that every other consumer downstream will reject, so it is worth being deliberate about. - Single-quoted values report a different message —
Unexpected character (''' (code 39))— because a quote is a character Jackson recognises but did not expect there.