Skip to content

A fast Java JSON schema validator that supports draft V4, V6, V7, V2019-09 and V2020-12

License

Notifications You must be signed in to change notification settings

networknt/json-schema-validator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

json-schema-validator

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.

Why to use this library?

  • 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.

Maven installation

Add the following to your pom.xml:

<dependency>
    <groupId>com.networknt</groupId>
    <artifactId>json-schema-validator</artifactId>
    <version>0.1.0</version>
</dependency>

Quickstart

		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));