Referencing a local relative file in a JSON Schema?

What you need there is being able to reference your files using an absolute URI.

Supposing you are using the stable version (ie 2.0.2), load your schema using this method.

Given where your file is located, use:

final JsonSchema schema 
    = factory.getJsonSchema("resource:/json/schema/MySchema.schema.json");

This means URI resolution in this schema will be made relatively to this (loading) URI; so, refering to your MyBoolean.json, you will do:

{
    "$ref": "MyBoolean.json#/pointer/into/file"
}

If it is located at, for instance, /json/schema/subschemas then you will write:

{
    "$ref": "subschemas/MyBoolean.json#/pointer/into/file"
}

Parents also work etc.


Note that as noted in the README, 2.1.x is a development version! I am currently reworking the API...


The following solution worked for me. The path is relative to location where I run mvn goals.

"items": {
                "type": "object",
                "$ref": "file:src/xyz/abc/lmn/DeviceRecord.json"
         }

Here file: is the path from where you are executing the maven goal.