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
*[JSON report of the failures](#json-report-of-the-failures)
@@ -13,7 +14,7 @@
13
14
*[Resolution scopes](#resolution-scopes)
14
15
15
16
16
-
This project is an implementation of the [JSON Schema Core Draft v4][draft-zyp-json-schema-04]specification.
17
+
This project is an implementation of the JSON Schema [Draft v4][draft-zyp-json-schema-04]and [Draft-6](https://tools.ietf.org/html/draft-wright-json-schema-01) specifications.
17
18
It uses the [org.json API](http://stleary.github.io/JSON-java/) (created by Douglas Crockford) for representing JSON data.
18
19
19
20
# When to use this library?
@@ -23,6 +24,7 @@ But - as you may have already discovered - there is also an [other Java implemen
23
24
of the JSON Schema specification. So here are some advices about which one to use:
24
25
* if you use Jackson to handle JSON in Java code, then [daveclayton/json-schema-validator] is obviously a better choice, since it uses Jackson
25
26
* if you want to use the [org.json API](http://www.json.org/java/) then this library is the better choice
27
+
* if you need JSON Schema Draft 6 support, then you need this library.
26
28
* if you want to use anything else for handling JSON (like GSON or javax.json), then you are in a little trouble, since
27
29
currently there is no schema validation library backed by these libraries. It means that you will have to parse the JSON
28
30
twice: once for the schema validator, and once for your own processing. In a case like that, this library is probably still
@@ -37,12 +39,21 @@ Add the following to your `pom.xml`:
JSON Schema has currently 3 major releases, Draft 3, Draft 4 and Draft 6. This library implements the 2 newer ones, you can have a quick look at the differences [here](https://github.com/json-schema-org/json-schema-spec/wiki/FAQ:-draft-wright-json-schema%5B-validation%5D-01#changes).
88
+
Since the two versions have a number of differences - and draft 6 is not backwards-compatible with draft 4 - it is good to know which version will you use.
89
+
90
+
The best way to denote the JSON Schema version you want to use is to include its meta-schema URL in the document root with the `"$schema"` key. This is a common notation, facilitated by the library to determine which version should be used.
91
+
92
+
Quick reference:
93
+
* if there is `"$schema": "http://json-schema.org/draft-04/schema"` in the schema root, then Draft 4 will be used
94
+
* if there is `"$schema": "http://json-schema.org/draft-06/schema"` in the schema root, then Draft 6 will be used
95
+
* if none of these is found then Draft 4 will be assumed as default
96
+
97
+
If you want to specify the meta-schema version explicitly then you can change the default from Draft 4 to Draft 6 by configuring the loader this way:
98
+
99
+
```java
100
+
SchemaLoader loader =SchemaLoader.builder()
101
+
.schemaJson(yourSchemaJSON)
102
+
.draftV6Support()
103
+
.build();
104
+
Schema schema = loader.load().build();
105
+
```
106
+
74
107
## Investigating failures
75
108
76
109
@@ -169,9 +202,13 @@ following keys:
169
202
*`"keyword"`: the JSON Schema keyword which was violated
170
203
*`"pointerToViolation"`: a JSON Pointer denoting the path from the input document root to its fragment which caused
171
204
the validation failure
205
+
*`"schemaLocation"`: a JSON Pointer denoting the path from the schema JSON root to the violated keyword
172
206
*`"causingExceptions"`: a (possibly empty) array of sub-exceptions. Each sub-exception is represented as a JSON object,
173
207
with the same structure as described in this listing. See more above about causing exceptions.
174
208
209
+
Please take into account that the complete failure report is a *hierarchical tree structure*: sub-causes of a cause can
210
+
be obtained using `#getCausingExceptions()` .
211
+
175
212
176
213
## Format validators
177
214
@@ -185,6 +222,12 @@ Starting from version `1.2.0` the library supports the [`"format"` keyword][draf
185
222
* ipv4
186
223
* ipv6
187
224
* uri
225
+
226
+
If you use the library in Draft 6 mode, then the followings are also supported:
227
+
228
+
* uri-reference
229
+
* uri-template
230
+
* json-pointer
188
231
189
232
The library also supports adding custom format validators. To use a custom validator basically you have to
0 commit comments