Given the following JSON file

{  "posts" : [ ]}

Java import this file and adds an extra character right at the beginning

This results in the following error when that JSON is parsed:

com.fasterxml.jackson.core.JsonParseException: Unexpected character ('-' (code 65279 / 0xfeff)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
 at [Source: {  "posts" : [ ]}; line: 1, column: 2]

	at com.fasterxml.jackson.core.JsonParser._constructError(
	at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(
	at com.fasterxml.jackson.core.base.ParserMinimalBase._reportUnexpectedChar(
	at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._handleOddValue(
	at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextToken(
	at com.fasterxml.jackson.databind.ObjectMapper._initForReading(
	at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(

Short answer solution

Replacing the first occurrence of the extra added string with a method such as the following should fix this issue:

  public String cleanUpJsonBOM(String json) {
      return json.trim().replaceFirst("\ufeff", "");


If we attempt to modify the “cleanUpJsonBOM()” method to replace the extra character with something else, such as “HEREIAM”:

  public String cleanUpJsonBOM(String json) {
      return json.trim().replaceFirst("\ufeff", "HEREIAM");

We will then get the following string:

  HEREIAM{  "posts": [  ]}

There’s our culprit. Without replacing this bytecode, the “\ufeff” characters would not be visible in debug mode, only within the stacktrace. It is only after replacing these characters that we can detect where the extra BOM was added. The root of the problem lies in added byte order marks at the beginning of text streams, which are used to signal needed properties to the text stream consumer.

Fortunately, Mark S. Kolich detected this problem with .XML files, which provided a clue towards solving the issue in this post.