{"record":{"id":"b5e267d45d9d8f2a","repo":"apache/hadoop","slug":"json-parser-error-0-b5e267","errorCode":null,"errorMessage":"JSON parser error, {0}","messagePattern":"JSON parser error, (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/client/HttpFSUtils.java","lineNumber":147,"sourceCode":"   * @throws IOException thrown if the <code>InputStream</code> could not be\n   * JSON parsed.\n   */\n  public static Object jsonParse(HttpURLConnection conn) throws IOException {\n    try {\n      String contentType = conn.getContentType();\n      if (contentType != null) {\n        final MediaType parsed = MediaType.valueOf(contentType);\n        if (!MediaType.APPLICATION_JSON_TYPE.isCompatible(parsed)) {\n          throw new IOException(\"Content-Type \\\"\" + contentType\n              + \"\\\" is incompatible with \\\"\" + MediaType.APPLICATION_JSON\n              + \"\\\" (parsed=\\\"\" + parsed + \"\\\")\");\n        }\n      }\n      JSONParser parser = new JSONParser();\n      return parser.parse(\n          new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8));\n    } catch (ParseException ex) {\n      throw new IOException(\"JSON parser error, \" + ex.getMessage(), ex);\n    }\n  }\n}\n","sourceCodeStart":129,"sourceCodeEnd":151,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/client/HttpFSUtils.java#L129-L151","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Capture the raw body (curl or wire-level logging) to see exactly where JSON parsing breaks","Check the HttpFS server log at the same timestamp for a stack trace explaining the truncated response","Align client and server Hadoop versions","If a proxy is in play, disable response buffering/rewriting for /webhdfs/v1 and retry"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  Object json = HttpFSUtils.jsonParse(conn);\n} catch (IOException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"JSON parser error\")) {\n    // body not valid JSON despite (missing) content-type: dump body, check server log and versions\n    String body = new String(conn.getErrorStream() != null ? conn.getErrorStream().readAllBytes() : new byte[0], StandardCharsets.UTF_8);\n    LOG.error(\"Non-JSON body from {}\", conn.getURL(), e);\n  }\n  throw e;\n}","preventionTips":["Version-lock client and server; test JSON endpoints after each upgrade","Disable proxy response buffering/rewrite on /webhdfs/v1","Correlate client parse failures with server logs by timestamp to find serialization crashes"],"tags":["webhdfs","httpfs","json-parse","truncated-response","client-server-skew"],"backgroundTag":"malformed-json-response","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}