{"record":{"id":"97ff6892dfefee42","repo":"apache/hadoop","slug":"failure-parsing-json-document-je-getmessage","errorCode":null,"errorMessage":"Failure parsing JSON document: ${je.getMessage()}","messagePattern":"Failure parsing JSON document: (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/jobhistory/JSONHistoryViewerPrinter.java","lineNumber":80,"sourceCode":"   * machine-readable JSON format.\n   * @param ps the {@link PrintStream} to print to\n   * @throws IOException when a problem occurs while printing\n   */\n  @Override\n  public void print(PrintStream ps) throws IOException {\n    json = new JSONObject();\n\n    Writer writer = null;\n    try {\n      printJobDetails();\n      printTaskSummary();\n      printTasks();\n\n      writer = new OutputStreamWriter(ps, StandardCharsets.UTF_8);\n      json.write(writer);\n      writer.flush();\n    } catch (JSONException je) {\n      throw new IOException(\"Failure parsing JSON document: \" + je.getMessage(),\n          je);\n    } finally {\n      if (writer != null) {\n        writer.close();\n      }\n    }\n  }\n\n  private void printJobDetails() throws JSONException {\n    json.put(\"hadoopJob\", job.getJobId().toString());\n    json.put(\"user\", job.getUsername());\n    json.put(\"jobName\", job.getJobname());\n    json.put(\"jobConf\", job.getJobConfPath());\n    json.put(\"submittedAt\", job.getSubmitTime());\n    json.put(\"launchedAt\", job.getLaunchTime());\n    json.put(\"finishedAt\", job.getFinishTime());\n    json.put(\"status\", ((job.getJobStatus() == null) ?\n        \"Incomplete\" :job.getJobStatus()));","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/jobhistory/JSONHistoryViewerPrinter.java#L62-L98","documentation":"JSONHistoryViewerPrinter assembles the job view into an org.json JSONObject and streams it out; any JSONException raised while building (problematic puts) or writing the document is wrapped as IOException(\"Failure parsing JSON document: <je.getMessage()>\", je). The underlying org.json message names the actual problem.","triggerScenarios":"Running HistoryViewer with format \"json\" on a history whose parsed job data triggers a JSONException - e.g. null/odd values put into the JSON object for abnormal jobs (killed jobs with unset finish times), or an I/O failure while the JSON writer flushes to the output stream.","commonSituations":"JSON output on incomplete/abnormal job histories; piping JSON viewer output into a closed/full output stream; automation scraping JSON for many jobs hitting one malformed record.","solutions":["Read the wrapped JSONException message to identify the offending field/operation.","View the same file in the default human format ('human' printer) which tolerates the same data - if it prints, the issue is JSON-specific.","Retry the JSON view on a history from a normally-completed job; abnormal (killed/failed-early) jobs can carry nulls that trip the printer.","If a specific field consistently fails, patch the printer to null-guard that put and report it upstream with the JSONException message."],"exampleFix":"# before\nhadoop job -history -format json <path>/job_*.jhist 2>&1 | head\n# IOException: Failure parsing JSON document: ...\n\n# after: same file, tolerant printer\nhadoop job -history <path>/job_*.jhist | head","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"catch (IOException e) when printing JSON history: if message starts with \"Failure parsing JSON document\", retry the same file with the human-format printer (new HumanReadableHistoryViewerPrinter path via format \"human\") before giving up.","preventionTips":["Default automation to the human printer; use JSON only where needed.","Expect abnormal (killed/failed-early) jobs to be the ones that trip JSON output.","Capture the wrapped JSONException message to identify the offending field before patching."],"tags":["hadoop","mapreduce","jobhistory","json","output-format","ioexception"],"backgroundTag":"json-serialization-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}