A Java json schema validator that support json schema draft v4
This project is an implementation of the JSON Schema Core Draft v4 specification. It uses the Jackson for json parsing.
- It is the fastest Java Json Schema Validator as far as I know. Here is the testing result compare with other two open source implementations. It is about 32 times faster than fge and 5 times faster than everit.
fge: 7130ms
everit-org: 1168ms
networknt: 223ms
You can run the performance tests for three libraries from https://github.com/networknt/json-schema-validator-perftest
- It uses jackson which is the most popular JSON parser in Java.
Add the following to your pom.xml
:
<dependency>
<groupId>com.networknt</groupId>
<artifactId>json-schema-validator</artifactId>
<version>0.1.0</version>
</dependency>
JsonSchema schema = getJsonSchemaFromStringContent("{\"enum\":[1, 2, 3, 4],\"enumErrorCode\":\"Not in the list\"}");
JsonNode node = getJsonNodeFromStringContent("7");
Set<ValidationMessage> errors = schema.validate(node);
assertThat(errors.size(), is(1));