apache/hadoop · error · IOException

JSON parser error, {0}

Error message

JSON parser error, {0}

What it means

HttpFSUtils.jsonParse() parses the response body with json-simple after the Content-Type check; a ParseException is wrapped as IOException("JSON parser error, " + cause). Reaching this line means the Content-Type was absent or JSON-compatible but the bytes themselves are not valid JSON. Typical causes are truncated or empty bodies served with status 200.

Source

Thrown at hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/client/HttpFSUtils.java:147

   * @throws IOException thrown if the <code>InputStream</code> could not be
   * JSON parsed.
   */
  public static Object jsonParse(HttpURLConnection conn) throws IOException {
    try {
      String contentType = conn.getContentType();
      if (contentType != null) {
        final MediaType parsed = MediaType.valueOf(contentType);
        if (!MediaType.APPLICATION_JSON_TYPE.isCompatible(parsed)) {
          throw new IOException("Content-Type \"" + contentType
              + "\" is incompatible with \"" + MediaType.APPLICATION_JSON
              + "\" (parsed=\"" + parsed + "\")");
        }
      }
      JSONParser parser = new JSONParser();
      return parser.parse(
          new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8));
    } catch (ParseException ex) {
      throw new IOException("JSON parser error, " + ex.getMessage(), ex);
    }
  }
}

View on GitHub (pinned to 2add963021)

Solutions

  1. Capture the raw body (curl or wire-level logging) to see exactly where JSON parsing breaks
  2. Check the HttpFS server log at the same timestamp for a stack trace explaining the truncated response
  3. Align client and server Hadoop versions
  4. If a proxy is in play, disable response buffering/rewriting for /webhdfs/v1 and retry
Defensive patterns

Strategy: try-catch

Try / catch

try {
  Object json = HttpFSUtils.jsonParse(conn);
} catch (IOException e) {
  if (e.getMessage() != null && e.getMessage().startsWith("JSON parser error")) {
    // body not valid JSON despite (missing) content-type: dump body, check server log and versions
    String body = new String(conn.getErrorStream() != null ? conn.getErrorStream().readAllBytes() : new byte[0], StandardCharsets.UTF_8);
    LOG.error("Non-JSON body from {}", conn.getURL(), e);
  }
  throw e;
}

Prevention

When it happens

Trigger: Server returns 200 with an empty body (filter bug), a chunked response cut off mid-stream by a proxy, a BOM-prefixed or HTML body mislabeled application/json, or version skew where the server emits a JSON grammar the client parser rejects.

Common situations: Response-buffering bug in a fronting proxy; HttpFS server exception half-way through serialization still producing 200; upgrading one side of client/server without the other; connection reset during large LISTSTATUS responses.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/b5e267d45d9d8f2a. Report an issue: GitHub.