Unexpected character ('}' (code 125))
com.fasterxml.jackson.core.JsonParseException: Unexpected character ('}' (code 125)): was expecting double-quote to start field name
Where JSON.parse stops
"id": 7,
"tags": ["a", "b"],
}What it means
Jackson gives you the character it found, its decimal code, and then what it wanted instead. Read the second half first. "was expecting double-quote to start field name" (Jackson 3 says "property name") means it was waiting for the next key, which is exactly what a trailing comma promises and never delivers.
Last verified on Jackson 2.21 and 3.1; Spring 6.2 and 7.0.
It opens with the error marked. Nothing is uploaded. Find where the error is.
- Usually
- (code 125): a trailing comma before a closing brace(code 93): a trailing comma inside an array(code 60): the document is HTML(code 39): single quotes(code 47): a comment(code 97), or any letter: an unquoted key
- Fix
- Delete the comma before the closing
}or].
The fix
Delete the comma before the closing } or ]. A comma goes between two values and never after the last one, which is exactly where a code generator or a hand edit tends to leave one.
{
"id": 7,
"tags": ["a", "b"],
}Line 3: delete ,.
{
"id": 7,
"tags": ["a", "b"]
}How the message appears
Jackson 2 first, then Jackson 3, then what Spring shows. The number in brackets is the decimal code point of the character it found, which is what makes these messages searchable but unreadable. Jackson 2 says "field name" and Jackson 3 says "property name". The lines after the Spring ones are Jackson 2 wording for other characters.
- com.fasterxml.jackson.core.JsonParseException: Unexpected character ('}' (code 125)): was expecting double-quote to start field name
- at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); line: 4, column: 1]
- tools.jackson.core.exc.StreamReadException: Unexpected character ('}' (code 125)): was expecting double-quote to start property name
- at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); byte offset: #UNKNOWN]
- org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Unexpected character ('}' (code 125)): was expecting double-quote to start field name
- org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Unexpected character ('}' (code 125)): was expecting double-quote to start property name
- Unexpected character ('<' (code 60)): expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
- Unexpected character (']' (code 93)): expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
- Unexpected character ('/' (code 47)): maybe a (non-standard) comment? (not recognized as one since Feature 'ALLOW_COMMENTS' not enabled for parser)
- Unexpected character ('a' (code 97)): was expecting double-quote to start field name
- Unexpected character (''' (code 39)): was expecting double-quote to start field name
What causes it
(code 125): a trailing comma before a closing brace
The comma said another key was coming and the closing brace turned up instead. Jackson reports the brace, so the message points one line past the comma that caused it.
(code 93): a trailing comma inside an array
The same mistake, one level in.
93is].(code 60): the document is HTML
60is<. You have an error page, a login redirect or a proxy response. No amount of editing the JSON will help, because there is no JSON.(code 39): single quotes
39is'. Fine in JavaScript and Python source, never valid in JSON.(code 47): a comment
47is/, the start of//or/*. JSON has no comments. Jackson says so in the message:maybe a (non-standard) comment?, and that theALLOW_COMMENTSfeature is not enabled.(code 97), or any letter: an unquoted key
The key is a bare word like
{active: true}.97is the lettera, and the code changes with the first letter of your key. Jackson wants a double quote there, so the message endswas expecting double-quote to start field name(Jackson 3:property name).
Worth knowing
NoteThe codes you will run into: 123 {, 125 }, 91 [, 93 ], 44 ,, 58 :, 34 ", 39 ', 47 /, 60 <, 10 newline.
NoteA very low code like (code 0) or (code 1) means you are parsing binary, or text that was decoded with the wrong charset. Look for a gzipped body being read as text, or a byte order mark.