Skip to content
Advertisement

org.everit.json.schema.SchemaException: #: could not determine version

A SchemaException gets thrown saying the version could not be determined as the title says. The schema version is clearly in the schema. This is all before data validation. Any ideas why this error gets thrown?

My schema is as follows:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$defs": {},
  "type": "array",
  "items": {
    "type": "object",
    "properties": {
      "randomString": {
        "type": "string"
      }
    }
  }
}
And Java code:

JSONParser jsonParser = new JSONParser();
                String schemaPath = new File("").getAbsolutePath() + schema.json;
                Object schemaObj = jsonParser.parse(new FileReader(schemaPath));
                org.json.simple.JSONObject schemaJson = (org.json.simple.JSONObject) schemaObj;
                JSONObject rawSchema = new JSONObject(schemaJson.toString());
                //This is where the SchemaException gets thrown, the line after this comment
                Schema schema = SchemaLoader.load(rawSchema);
                //schema.validate(json);

Advertisement

Answer

The library doesn’t support draft 2020-12 and 2019-09.

You will have to use draft 7 for now (or use an other library).

Edit: the correct meta-schema URL for draft 7 is "$schema": "https://json-schema.org/draft-07/schema"

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement