stanfordnlp/CoreNLP · error · RuntimeException

Couldn't parse + json

Error message

Couldn't parse 
 + json

What it means

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.

Solutions

  1. Inspect getCause() to identify the precise decode failure (bad JSON vs missing/wrong-typed field).
  2. Validate the JSON parses (Json.createReader(...).readObject()) and has the required typed fields before calling readFromJSON.
  3. Fix or regenerate the source .json file from the dataset.
  4. Catch RuntimeException, log the offending json string, and skip the bad record in bulk-processing loops.

Example fix

// before
SceneGraphImage img = SceneGraphImage.readFromJSON(line); // throws on bad line
// after
try {
  SceneGraphImage img = SceneGraphImage.readFromJSON(line);
} catch (RuntimeException e) {
  log.warn("Skipping unparseable record: " + e.getCause());
  continue;
}
Defensive patterns

Strategy: try-catch

Validate before calling

try (JsonReader r = Json.createReader(new StringReader(json))) { r.readObject(); } // parse check
catch (JsonParsingException e) { throw new IllegalArgumentException("not valid JSON", e); }

Try / catch

try {
  return SceneGraphImage.readFromJSON(obj);
} catch (RuntimeException e) {
  Throwable cause = e.getCause();
  log.warn("Couldn't parse record: " + cause + " json=" + json);
  return null; // skip bad record
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/31d63e1754488fd7. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/scenegraph/image/SceneGraphImage.java:101

      }

      img.id = obj.getInt("id");
      Number height = obj.getInt("height");
      Number width = obj.getInt("width");
      if (height == null) {
        throw new NullPointerException("Image does not have height");
      }
      if (width == null) {
        throw new NullPointerException("Image does not have width");
      }
      img.height = height.intValue();
      img.width = width.intValue();

      img.url = obj.getString("url");

      return img;
    } catch (RuntimeException e) {
      throw new RuntimeException("Couldn't parse \n" + json, e);
    }
  }

  @SuppressWarnings("unchecked")
  public String toJSON() {
    JsonObjectBuilder json = Json.createObjectBuilder();
    json.add("id", this.id);
    json.add("height", this.height);
    json.add("width", this.width);
    json.add("url", this.url);

    JsonArrayBuilder attributes = Json.createArrayBuilder();
    for (SceneGraphImageAttribute attr : this.attributes) {
      attributes.add(attr.toJSONObject(this));
    }

    json.add("attributes", attributes.build());

View on GitHub (pinned to 1b7edd19c4)