You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is an implementation of the [JSON Schema Core Draft v4](http://json-schema.org/latest/json-schema-core.html) specification for OpenAPI 3.0. It uses the [Jackson](https://github.com/FasterXML/jackson) for json parsing.
This is a Java implementation of the [JSON Schema Core Draft v4-v7](http://json-schema.org/latest/json-schema-core.html) specification for JSON schema validation. In addition, it also works for OpenAPI 3.0 request/response validation with some [configuration flags](doc/config.md). The default JSON parser is the [Jackson](https://github.com/FasterXML/jackson) that is the most popular one. As it is a key component in our [light-4j](https://github.com/networknt/light-4j) microservices framework to validate request/response against OpenAPI specification for [light-rest-4j](http://www.networknt.com/style/light-rest-4j/) and RPC schema for [light-hybrid-4j](http://www.networknt.com/style/light-hybrid-4j/) at runtime, performance is the most important aspect in the design.
13
+
14
+
## Why this library
15
15
16
-
A Java json schema validator that supports json schema draft v4. It is a key component in our
17
-
[light-4j](https://github.com/networknt/light-4j) microservices framework to validate request
18
-
against OpenAPI specification for [light-rest-4j](http://www.networknt.com/style/light-rest-4j/)
19
-
and RPC schema for [light-hybrid-4j](http://www.networknt.com/style/light-hybrid-4j/) at runtime.
16
+
#### Performance
20
17
18
+
It is the fastest Java JSON Schema Validator as far as I know. Here is the testing result compare with the other two open-source implementations. It is about 32 times faster than the Fge and five times faster than the Everit.
21
19
22
-
*[Why to use this library?](#why-to-use-this-library)
23
-
*[Maven installation](#maven-installation)
24
-
*[Quickstart](#quickstart)
20
+
fge: 7130ms
25
21
22
+
everit-org: 1168ms
26
23
24
+
networknt: 223ms
27
25
28
-
# Why to use this library?
26
+
You can run the performance tests for three libraries from [https://github.com/networknt/json-schema-validator-perftest](https://github.com/networknt/json-schema-validator-perftest)
29
27
30
-
* It is the fastest Java Json Schema Validator as far as I know. Here is the testing result compare with other two open
31
-
source implementations. It is about 32 times faster than fge and 5 times faster than everit.
28
+
#### Parser
32
29
30
+
It uses Jackson that is the most popular JSON parser in Java. If you are using Jackson parser already in your project, it is natural to choose this library over others for schema validation.
33
31
34
-
fge: 7130ms
32
+
#### Dependency
35
33
36
-
everit-org: 1168ms
34
+
Following the design principle of the Light Platform, this library has minimum dependencies to ensure there are no dependency conflicts when using it.
37
35
38
-
networknt: 223ms
36
+
Here are the dependencies.
39
37
40
-
You can run the performance tests for three libraries from [https://github.com/networknt/json-schema-validator-perftest](https://github.com/networknt/json-schema-validator-perftest)
38
+
```
39
+
<dependency>
40
+
<groupId>com.fasterxml.jackson.core</groupId>
41
+
<artifactId>jackson-databind</artifactId>
42
+
<version>${version.jackson}</version>
43
+
</dependency>
44
+
<dependency>
45
+
<groupId>org.slf4j</groupId>
46
+
<artifactId>slf4j-api</artifactId>
47
+
<version>${version.slf4j}</version>
48
+
</dependency>
49
+
<dependency>
50
+
<groupId>org.apache.commons</groupId>
51
+
<artifactId>commons-lang3</artifactId>
52
+
<version>${version.common-lang3}</version>
53
+
</dependency>
54
+
```
55
+
56
+
#### Community
41
57
42
-
* It uses Jackson which is the most popular JSON parser in Java.
58
+
This library is very active with a lot of contributors. New features and bug fixes are handled quickly by the team members. Because it is an essential dependency of the [light-4j](https://github.com/networknt/light-4j) framework in the same GitHub organization, it will be evolved and maintained along with the framework.
43
59
60
+
## Prerequisite
44
61
62
+
The library supports Java 8 and up. If you want to build from the source code, you need to install JDK 8 locally. To support multiple version of JDK, you can use [SDKMAN](https://www.networknt.com/tool/sdk/)
45
63
46
-
## Maven installation
64
+
## Dependency
47
65
48
-
Add the following to your `pom.xml`:
66
+
This package is available on Maven central.
67
+
68
+
Maven:
49
69
50
70
```xml
51
71
<dependency>
@@ -55,113 +75,58 @@ Add the following to your `pom.xml`:
55
75
</dependency>
56
76
```
57
77
58
-
## Quickstart
59
-
60
-
To use the validator, you need to have both JsonSchema object and JsonNode object constructed and there are many ways to do that. Here is my
61
-
base test class that shows you several way to construct these from String, Stream, Url and JsonNode. Pay attention on JsonSchemaFactory class
62
-
as it is the way to construct JsonSchema object.
63
-
64
-
65
-
```java
66
-
/*
67
-
* Copyright (c) 2016 Network New Technologies Inc.
68
-
*
69
-
* Licensed under the Apache License, Version 2.0 (the "License");
70
-
* you may not use this file except in compliance with the License.
71
-
* You may obtain a copy of the License at
72
-
*
73
-
* http://www.apache.org/licenses/LICENSE-2.0
74
-
*
75
-
* Unless required by applicable law or agreed to in writing, software
76
-
* distributed under the License is distributed on an "AS IS" BASIS,
77
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
78
-
* See the License for the specific language governing permissions and
For the latest version, please check the [release](https://github.com/networknt/json-schema-validator/releases) page.
152
87
153
-
```
88
+
## [Quick Start](doc/quickstart.md)
154
89
155
90
## [Configuration](doc/config.md)
156
91
157
92
## Known issues
158
93
159
-
I have just updated the test suites from the [official website](https://github.com/json-schema-org/JSON-Schema-Test-Suite) as the old ones were copied from another Java validator. Now there are several issues that need to be addressed. All of them are edge cases in my opinion
160
-
but need to be investigated. As my old test suites were inherited from another Java JSON Schema Validator, I guess other Java Validator would have the same issues as these issues are in the Java Language itself.
94
+
I have just updated the test suites from the [official website](https://github.com/json-schema-org/JSON-Schema-Test-Suite) as the old ones were copied from another Java validator. Now there are several issues that need to be addressed. All of them are edge cases, in my opinion, but need to be investigated. As my old test suites were inherited from another Java JSON Schema Validator, I guess other Java Validator would have the same issues as these issues are in the Java language itself.
Thanks to the following people who have contributed to this project. If you are using this library, please consider to be a sponsor for one of the contributors.
103
+
104
+
[@stevehu](https://github.com/sponsors/stevehu)
105
+
[@jiachen1120](https://github.com/jiachen1120)
106
+
[@BalloonWen](https://github.com/BalloonWen)
107
+
[@eskabetxe](https://github.com/eskabetxe)
108
+
[@ddobrin](https://github.com/ddobrin)
109
+
[@ehrmann](https://github.com/ehrmann)
110
+
[@rhwood](https://github.com/rhwood)
111
+
[@nitin1891](https://github.com/nitin1891)
112
+
[@jawaff](https://github.com/jawaff)
113
+
[@kosty](https://github.com/kosty)
114
+
[@chenyan71](https://github.com/chenyan71)
115
+
[@chrisken](https://github.com/chrisken)
116
+
[@NicholasAzar](https://github.com/NicholasAzar)
117
+
[@basinilya](https://github.com/basinilya)
118
+
119
+
For all contributors, please visit https://github.com/networknt/json-schema-validator/graphs/contributors
120
+
121
+
If you are a contributor, please join the [GitHub Sponsors](https://github.com/sponsors) and swithch the link to your sponsors dashboard via a PR.
To use the validator, you need to have both the JsonSchema object and JsonNode object constructed, and there are many ways to do that. Here is my base test class that shows you several ways to construct these from String, Stream, Url, and JsonNode. Pay attention to the JsonSchemaFactory class as it is the way to construct the JsonSchema object.
4
+
5
+
```java
6
+
/*
7
+
* Copyright (c) 2016 Network New Technologies Inc.
8
+
*
9
+
* Licensed under the Apache License, Version 2.0 (the "License");
10
+
* you may not use this file except in compliance with the License.
11
+
* You may obtain a copy of the License at
12
+
*
13
+
* http://www.apache.org/licenses/LICENSE-2.0
14
+
*
15
+
* Unless required by applicable law or agreed to in writing, software
16
+
* distributed under the License is distributed on an "AS IS" BASIS,
17
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+
* See the License for the specific language governing permissions and
And the following is one of the test cases in one of the test classes that extend from the above base class. As you can see, it constructs JsonSchema and JsonNode from String.
85
+
86
+
```java
87
+
JsonSchema schema = getJsonSchemaFromStringContent("{\"enum\":[1, 2, 3, 4],\"enumErrorCode\":\"Not in the list\"}");
0 commit comments