{"record":{"id":"31d63e1754488fd7","repo":"stanfordnlp/CoreNLP","slug":"couldn-t-parse-json","errorCode":null,"errorMessage":"Couldn't parse \n + json","messagePattern":"Couldn't parse \n \\+ json","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/scenegraph/image/SceneGraphImage.java","lineNumber":101,"sourceCode":"      }\n\n      img.id = obj.getInt(\"id\");\n      Number height = obj.getInt(\"height\");\n      Number width = obj.getInt(\"width\");\n      if (height == null) {\n        throw new NullPointerException(\"Image does not have height\");\n      }\n      if (width == null) {\n        throw new NullPointerException(\"Image does not have width\");\n      }\n      img.height = height.intValue();\n      img.width = width.intValue();\n\n      img.url = obj.getString(\"url\");\n\n      return img;\n    } catch (RuntimeException e) {\n      throw new RuntimeException(\"Couldn't parse \\n\" + json, e);\n    }\n  }\n\n  @SuppressWarnings(\"unchecked\")\n  public String toJSON() {\n    JsonObjectBuilder json = Json.createObjectBuilder();\n    json.add(\"id\", this.id);\n    json.add(\"height\", this.height);\n    json.add(\"width\", this.width);\n    json.add(\"url\", this.url);\n\n    JsonArrayBuilder attributes = Json.createArrayBuilder();\n    for (SceneGraphImageAttribute attr : this.attributes) {\n      attributes.add(attr.toJSONObject(this));\n    }\n\n    json.add(\"attributes\", attributes.build());\n","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/scenegraph/image/SceneGraphImage.java#L83-L119","documentation":"SceneGraphImage.readFromJSON wraps the entire JSON parsing block in a catch(RuntimeException) that rethrows RuntimeException(\"Couldn't parse \\n\" + json, e) at src/edu/stanford/nlp/scenegraph/image/SceneGraphImage.java:101. Any runtime failure inside JSON decoding — malformed JSON, wrong field types (e.g. getString on an int), or the missing height/width NPEs — surfaces with this message and the real cause attached.","triggerScenarios":"Passing malformed JSON text or a JsonObject whose fields have unexpected types (non-numeric id/height/width, missing url) to readFromJSON; also triggered by the internal height/width null checks.","commonSituations":"Reading corrupted or hand-edited .json scene-graph files; dataset lines that are not valid JSON; JSON produced by a different schema version where a field's type changed.","solutions":["Inspect getCause() to identify the precise decode failure (bad JSON vs missing/wrong-typed field).","Validate the JSON parses (Json.createReader(...).readObject()) and has the required typed fields before calling readFromJSON.","Fix or regenerate the source .json file from the dataset.","Catch RuntimeException, log the offending json string, and skip the bad record in bulk-processing loops."],"exampleFix":"// before\nSceneGraphImage img = SceneGraphImage.readFromJSON(line); // throws on bad line\n// after\ntry {\n  SceneGraphImage img = SceneGraphImage.readFromJSON(line);\n} catch (RuntimeException e) {\n  log.warn(\"Skipping unparseable record: \" + e.getCause());\n  continue;\n}","handlingStrategy":"try-catch","validationCode":"try (JsonReader r = Json.createReader(new StringReader(json))) { r.readObject(); } // parse check\ncatch (JsonParsingException e) { throw new IllegalArgumentException(\"not valid JSON\", e); }","typeGuard":null,"tryCatchPattern":"try {\n  return SceneGraphImage.readFromJSON(obj);\n} catch (RuntimeException e) {\n  Throwable cause = e.getCause();\n  log.warn(\"Couldn't parse record: \" + cause + \" json=\" + json);\n  return null; // skip bad record\n}","preventionTips":["Always inspect getCause() — the wrapper message is generic","Pre-validate JSON lines in bulk ingestion pipelines","Keep dataset files generated by scripts, not hand-edited"],"tags":["java","json","parse-error","scenegraph"],"backgroundTag":"json-parse-error","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}