Documentation: https://harrel56.github.io/json-schema
Java library implementing JSON schema specification:
- compatible with Java 8,
- support for all recent specification versions
:
- support for custom keywords,
- support for annotation collection,
- support for format validation (for a price of one additional dependency 😉),
- compatible with most of the JSON/YAML libraries (supported libraries),
- and no additional dependencies on top of that.
Check how it compares with other implementations:
- Bowtie - specification compliance (only mandatory behavior),
- Creek's benchmark - benchmark for JVM based implementations.
You can check out how it works here.
Please note that you will also need to include at least one of the supported JSON provider libraries (see JSON provider setup).
<dependency>
<groupId>dev.harrel</groupId>
<artifactId>json-schema</artifactId>
<version>1.8.2</version>
</dependency>
implementation 'dev.harrel:json-schema:1.8.2'
To validate JSON against a schema, you just need to invoke:
String schema = """
{
"type": "boolean"
}""";
String instance = "true";
boolean valid = new ValidatorFactory().validate(schema, instance).isValid();
For more details please visit the documentation.