Unexpected character ('}' (code 125))

ErrorJava

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.

broken.jsonFails to parse
{
  "id": 7,
  "tags": ["a", "b"],
}
JSON.parse stops at line 4, column 1.

Line 3: delete ,.

fixed.jsonParses
{
  "id": 7,
  "tags": ["a", "b"]
}
JSON.parse reads it.

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.

Console
  • 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

  1. (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.

  2. (code 93): a trailing comma inside an array

    The same mistake, one level in. 93 is ].

  3. (code 60): the document is HTML

    60 is <. 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.

  4. (code 39): single quotes

    39 is '. Fine in JavaScript and Python source, never valid in JSON.

  5. (code 47): a comment

    47 is /, the start of // or /*. JSON has no comments. Jackson says so in the message: maybe a (non-standard) comment?, and that the ALLOW_COMMENTS feature is not enabled.

  6. (code 97), or any letter: an unquoted key

    The key is a bare word like {active: true}. 97 is the letter a, and the code changes with the first letter of your key. Jackson wants a double quote there, so the message ends was 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.

What you put into the tools never leaves your browser. We count page views and keep them for 90 days. Accept and we also remember this browser, so a return visit is not counted as new. Privacy policy