1[Stack Overflow](https://stackoverflow.com/questions/tagged/light-4j) | 2[Google Group](https://groups.google.com/forum/#!forum/light-4j) | 3[Gitter Chat](https://gitter.im/networknt/json-schema-validator) | 4[Subreddit](https://www.reddit.com/r/lightapi/) | 5[Youtube](https://www.youtube.com/channel/UCHCRMWJVXw8iB7zKxF55Byw) | 6[Documentation](https://doc.networknt.com/library/json-schema-validator/) | 7[Contribution Guide](https://doc.networknt.com/contribute/) | 8 9[](https://github.com/networknt/json-schema-validator/actions/workflows/ci.yml) 10[](http://search.maven.org/#search%7Cga%7C1%7Cg%3Acom.networknt%20a%3Ajson-schema-validator) 11[](https://codecov.io/github/networknt/json-schema-validator?branch=master) 12[](https://www.javadoc.io/doc/com.networknt/json-schema-validator) 13 14This is a Java implementation of the [JSON Schema Core Draft v4, v6, v7, v2019-09 and v2020-12](http://json-schema.org/latest/json-schema-core.html) specification for JSON schema validation. This implementation supports [Customizing Meta-Schemas, Vocabularies, Keywords and Formats](doc/custom-meta-schema.md). 15 16In addition, it also works for OpenAPI 3.0 request/response validation with some [configuration flags](doc/config.md). For users who want to collect information from a JSON node based on the schema, the [walkers](doc/walkers.md) can help. The JSON parser used is the [Jackson](https://github.com/FasterXML/jackson) parser. 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. 17 18## JSON Schema Specification compatibility 19 20[](https://bowtie.report/#/implementations/java-json-schema-validator) 21[](https://bowtie.report/#/dialects/draft2020-12) 22[](https://bowtie.report/#/dialects/draft2019-09) 23[](https://bowtie.report/#/dialects/draft7) 24[](https://bowtie.report/#/dialects/draft6) 25[](https://bowtie.report/#/dialects/draft4) 26 27Information on the compatibility support for each version, including known issues, can be found in the [Compatibility with JSON Schema versions](doc/compatibility.md) document. 28 29Since [Draft 2019-09](https://json-schema.org/draft/2019-09/json-schema-validation#rfc.section.7) the `format` keyword only generates annotations by default and does not generate assertions. 30 31This behavior can be overridden to generate assertions by setting the `setFormatAssertionsEnabled` to `true` in `SchemaValidatorsConfig` or `ExecutionConfig`. 32 33## Upgrading to new versions 34 35This library can contain breaking changes in `minor` version releases that may require code changes. 36 37Information on notable or breaking changes when upgrading the library can be found in the [Upgrading to new versions](doc/upgrading.md) document. 38 39The [Releases](https://github.com/networknt/json-schema-validator/releases) page will contain information on the latest versions. 40 41## Comparing against other implementations 42 43The [JSON Schema Validation Comparison](https://github.com/creek-service/json-schema-validation-comparison) project from Creek has an informative [Comparison of JVM based Schema Validation Implementations](https://www.creekservice.org/json-schema-validation-comparison/) which compares both the functional and performance characteristics of a number of different Java implementations. 44* [Functional comparison](https://www.creekservice.org/json-schema-validation-comparison/functional#summary-results-table) 45* [Performance comparison](https://www.creekservice.org/json-schema-validation-comparison/performance#json-schema-test-suite-benchmark) 46 47The [Bowtie](https://github.com/bowtie-json-schema/bowtie) project has a [report](https://bowtie.report/) that compares functional characteristics of different implementations, including non-Java implementations, but does not do any performance benchmarking. 48 49## Why this library 50 51#### Performance 52 53This should be the fastest Java JSON Schema Validator implementation. 54 55The following is the benchmark results from the [JSON Schema Validator Perftest](https://github.com/networknt/json-schema-validator-perftest) project that uses the [Java Microbenchmark Harness](https://github.com/openjdk/jmh). 56 57Note that the benchmark results are highly dependent on the input data workloads and schemas used for the validation. 58 59In this case this workload is using the Draft 4 specification and largely tests the performance of the evaluating the `properties` keyword. You may refer to [Results of performance comparison of JVM based JSON Schema Validation Implementations](https://www.creekservice.org/json-schema-validation-comparison/performance#json-schema-test-suite-benchmark) for benchmark results for more typical workloads 60 61If performance is an important consideration, the specific sample workloads should be benchmarked, as there are different performance characteristics when certain keywords are used. For instance the use of the `unevaluatedProperties` or `unevaluatedItems` keyword will trigger annotation collection in the related validators, such as the `properties` or `items` validators, and annotation collection will adversely affect performance. 62 63##### NetworkNT 1.3.1 64 65``` 66Benchmark Mode Cnt Score Error Units 67NetworkntBenchmark.testValidate thrpt 10 6776.693 ± 115.309 ops/s 68NetworkntBenchmark.testValidate:·gc.alloc.rate thrpt 10 971.191 ± 16.420 MB/sec 69NetworkntBenchmark.testValidate:·gc.alloc.rate.norm thrpt 10 165318.816 ± 0.459 B/op 70NetworkntBenchmark.testValidate:·gc.churn.G1_Eden_Space thrpt 10 968.894 ± 51.234 MB/sec 71NetworkntBenchmark.testValidate:·gc.churn.G1_Eden_Space.norm thrpt 10 164933.962 ± 8636.203 B/op 72NetworkntBenchmark.testValidate:·gc.churn.G1_Survivor_Space thrpt 10 0.002 ± 0.001 MB/sec 73NetworkntBenchmark.testValidate:·gc.churn.G1_Survivor_Space.norm thrpt 10 0.274 ± 0.218 B/op 74NetworkntBenchmark.testValidate:·gc.count thrpt 10 89.000 counts 75NetworkntBenchmark.testValidate:·gc.time thrpt 10 99.000 ms 76``` 77 78###### Everit 1.14.1 79 80``` 81Benchmark Mode Cnt Score Error Units 82EveritBenchmark.testValidate thrpt 10 3719.192 ± 125.592 ops/s 83EveritBenchmark.testValidate:·gc.alloc.rate thrpt 10 1448.208 ± 74.746 MB/sec 84EveritBenchmark.testValidate:·gc.alloc.rate.norm thrpt 10 449621.927 ± 7400.825 B/op 85EveritBenchmark.testValidate:·gc.churn.G1_Eden_Space thrpt 10 1446.397 ± 79.919 MB/sec 86EveritBenchmark.testValidate:·gc.churn.G1_Eden_Space.norm thrpt 10 449159.799 ± 18614.931 B/op 87EveritBenchmark.testValidate:·gc.churn.G1_Survivor_Space thrpt 10 0.001 ± 0.001 MB/sec 88EveritBenchmark.testValidate:·gc.churn.G1_Survivor_Space.norm thrpt 10 0.364 ± 0.391 B/op 89EveritBenchmark.testValidate:·gc.count thrpt 10 133.000 counts 90EveritBenchmark.testValidate:·gc.time thrpt 10 148.000 ms 91``` 92 93#### Functionality 94 95This implementation is tested against the [JSON Schema Test Suite](https://github.com/json-schema-org/JSON-Schema-Test-Suite). As tests are continually added to the suite, these test results may not be current. 96 97| Implementations | Overall | DRAFT_03 | DRAFT_04 | DRAFT_06 | DRAFT_07 | DRAFT_2019_09 | DRAFT_2020_12 | 98|-----------------|-------------------------------------------------------------------------|-------------------------------------------------------------------|---------------------------------------------------------------------|--------------------------------------------------------------------|------------------------------------------------------------------------|----------------------------------------------------------------------|------------------------------------------------------------------------| 99| NetworkNt | pass: r:4703 (100.0%) o:2369 (100.0%)<br>fail: r:0 (0.0%) o:1 (0.0%) | | pass: r:600 (100.0%) o:251 (100.0%)<br>fail: r:0 (0.0%) o:0 (0.0%) | pass: r:796 (100.0%) o:318 (100.0%)<br>fail: r:0 (0.0%) o:0 (0.0%) | pass: r:880 (100.0%) o:541 (100.0%)<br>fail: r:0 (0.0%) o:0 (0.0%) | pass: r:1201 (100.0%) o:625 (100.0%)<br>fail: r:0 (0.0%) o:0 (0.0%) | pass: r:1226 (100.0%) o:634 (99.8%)<br>fail: r:0 (0.0%) o:1 (0.2%) | 100 101* Note that this uses the ECMA 262 Validator option turned on for the `pattern` tests. 102 103#### Jackson Parser 104 105This library uses [Jackson](https://github.com/FasterXML/jackson) which is a Java JSON parser that is widely used in other projects. If you are already using the Jackson parser in your project, it is natural to choose this library over others for schema validation. 106 107#### YAML Support 108 109The library works with JSON and YAML on both schema definitions and input data. 110 111#### OpenAPI Support 112 113The OpenAPI 3.0 specification is using JSON schema to validate the request/response, but there are some differences. With a configuration file, you can enable the library to work with OpenAPI 3.0 validation. 114 115#### Minimal Dependencies 116 117Following the design principle of the Light Platform, this library has minimal dependencies to ensure there are no dependency conflicts when using it. 118 119##### Required Dependencies 120 121The following are the dependencies that will automatically be included when this library is included. 122 123```xml 124<dependency> 125 <!-- Used for logging --> 126 <groupId>org.slf4j</groupId> 127 <artifactId>slf4j-api</artifactId> 128 <version>${version.slf4j}</version> 129</dependency> 130 131<dependency> 132 <!-- Used to process JSON --> 133 <groupId>com.fasterxml.jackson.core</groupId> 134 <artifactId>jackson-databind</artifactId> 135 <version>${version.jackson}</version> 136</dependency> 137 138<dependency> 139 <!-- Used to process YAML --> 140 <groupId>com.fasterxml.jackson.dataformat</groupId> 141 <artifactId>jackson-dataformat-yaml</artifactId> 142 <version>${version.jackson}</version> 143</dependency> 144 145<dependency> 146 <!-- Used to validate RFC 3339 date and date-time --> 147 <groupId>com.ethlo.time</groupId> 148 <artifactId>itu</artifactId> 149 <version>${version.itu}</version> 150</dependency> 151``` 152 153##### Optional Dependencies 154 155The following are the optional dependencies that may be required for certain options. 156 157These are not automatically included and setting the relevant option without adding the library will result in a `ClassNotFoundException`. 158 159```xml 160<!-- This is required when setting setEcma262Validator(true) --> 161<dependency> 162 <!-- Used to validate ECMA 262 regular expressions --> 163 <groupId>org.jruby.joni</groupId> 164 <artifactId>joni</artifactId> 165 <version>${version.joni}</version> 166 <optional>true</optional> 167</dependency> 168``` 169 170##### Excludable Dependencies 171 172The following are required dependencies that are automatically included, but can be explicitly excluded if they are not required. 173 174The YAML dependency can be excluded if this is not required. Attempting to process schemas or input that are YAML will result in a `ClassNotFoundException`. 175 176```xml 177<dependency> 178 <groupId>com.networknt</groupId> 179 <artifactId>json-schema-validator</artifactId> 180 <exclusions> 181 <exclusion> 182 <groupId>com.fasterxml.jackson.dataformat</groupId> 183 <artifactId>jackson-dataformat-yaml</artifactId> 184 </exclusion> 185 </exclusions> 186</dependency> 187``` 188 189The Ethlo Time dependency can be excluded if accurate validation of the `date-time` format is not required. The `date-time` format will then use `java.time.OffsetDateTime` to determine if the `date-time` is valid . 190 191```xml 192<dependency> 193 <groupId>com.networknt</groupId> 194 <artifactId>json-schema-validator</artifactId> 195 <exclusions> 196 <exclusion> 197 <groupId>com.ethlo.time</groupId> 198 <artifactId>itu</artifactId> 199 </exclusion> 200 </exclusions> 201</dependency> 202``` 203 204#### Community 205 206This 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. 207 208## Prerequisite 209 210The 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/) 211 212## Usage 213 214### Adding the dependency 215 216This package is available on Maven central. 217 218#### Maven: 219 220```xml 221<dependency> 222 <groupId>com.networknt</groupId> 223 <artifactId>json-schema-validator</artifactId> 224 <version>1.4.0</version> 225</dependency> 226``` 227 228#### Gradle: 229 230```java 231dependencies { 232 implementation(group: 'com.networknt', name: 'json-schema-validator', version: '1.4.0'); 233} 234``` 235 236### Validating inputs against a schema 237 238The following example demonstrates how inputs are validated against a schema. It comprises the following steps. 239 240* Creating a schema factory with the default schema dialect and how the schemas can be retrieved. 241 * Configuring mapping the `$id` to a retrieval URI using `schemaMappers`. 242 * Configuring how the schemas are loaded using the retrieval URI using `schemaLoaders`. 243 For instance a `Map<String, String> schemas` containing a mapping of retrieval URI to schema data as a `String` can by configured using `builder.schemaLoaders(schemaLoaders -> schemaLoaders.schemas(schemas))`. This also accepts a `Function<String, String> schemaRetrievalFunction`. 244* Creating a configuration for controlling validator behavior. 245* Loading a schema from a schema location along with the validator configuration. 246* Using the schema to validate the data along with setting any execution specific configuration like for instance the locale or whether format assertions are enabled. 247 248```java 249// This creates a schema factory that will use Draft 2012-12 as the default if $schema is not specified 250// in the schema data. If $schema is specified in the schema data then that schema dialect will be used 251// instead and this version is ignored. 252JsonSchemaFactory jsonSchemaFactory = JsonSchemaFactory.getInstance(VersionFlag.V202012, builder -> 253 // This creates a mapping from $id which starts with https://www.example.org/ to the retrieval URI classpath:schema/ 254 builder.schemaMappers(schemaMappers -> schemaMappers.mapPrefix("https://www.example.org/", "classpath:schema/")) 255); 256 257SchemaValidatorsConfig config = new SchemaValidatorsConfig(); 258// By default JSON Path is used for reporting the instance location and evaluation path 259config.setPathType(PathType.JSON_POINTER); 260// By default the JDK regular expression implementation which is not ECMA 262 compliant is used 261// Note that setting this to true requires including the optional joni dependency 262// config.setEcma262Validator(true); 263 264// Due to the mapping the schema will be retrieved from the classpath at classpath:schema/example-main.json. 265// If the schema data does not specify an $id the absolute IRI of the schema location will be used as the $id. 266JsonSchema schema = jsonSchemaFactory.getSchema(SchemaLocation.of("https://www.example.org/example-main.json"), config); 267String input = "{\r\n" 268 + " \"main\": {\r\n" 269 + " \"common\": {\r\n" 270 + " \"field\": \"invalidfield\"\r\n" 271 + " }\r\n" 272 + " }\r\n" 273 + "}"; 274 275Set<ValidationMessage> assertions = schema.validate(input, InputFormat.JSON, executionContext -> { 276 // By default since Draft 2019-09 the format keyword only generates annotations and not assertions 277 executionContext.getConfig().setFormatAssertionsEnabled(true); 278}); 279``` 280 281### Validating a schema against a meta-schema 282 283The following example demonstrates how a schema is validated against a meta-schema. 284 285This is actually the same as validating inputs against a schema except in this case the input is the schema and the schema used is the meta-schema. 286 287Note that the meta-schemas for Draft 4, Draft 6, Draft 7, Draft 2019-09 and Draft 2020-12 are bundled with the library and these classpath resources will be used by default. 288 289```java 290JsonSchemaFactory jsonSchemaFactory = JsonSchemaFactory.getInstance(VersionFlag.V202012); 291 292SchemaValidatorsConfig config = new SchemaValidatorsConfig(); 293// By default JSON Path is used for reporting the instance location and evaluation path 294config.setPathType(PathType.JSON_POINTER); 295// By default the JDK regular expression implementation which is not ECMA 262 compliant is used 296// Note that setting this to true requires including the optional joni dependency 297// config.setEcma262Validator(true); 298 299// Due to the mapping the meta-schema will be retrieved from the classpath at classpath:draft/2020-12/schema. 300JsonSchema schema = jsonSchemaFactory.getSchema(SchemaLocation.of(SchemaId.V202012), config); 301String input = "{\r\n" 302 + " \"type\": \"object\",\r\n" 303 + " \"properties\": {\r\n" 304 + " \"key\": {\r\n" 305 + " \"title\" : \"My key\",\r\n" 306 + " \"type\": \"invalidtype\"\r\n" 307 + " }\r\n" 308 + " }\r\n" 309 + "}"; 310Set<ValidationMessage> assertions = schema.validate(input, InputFormat.JSON, executionContext -> { 311 // By default since Draft 2019-09 the format keyword only generates annotations and not assertions 312 executionContext.getConfig().setFormatAssertionsEnabled(true); 313}); 314``` 315### Results and output formats 316 317#### Results 318 319The following types of results are generated by the library. 320 321| Type | Description 322|-------------|------------------- 323| Assertions | Validation errors generated by a keyword on a particular input data instance. This is generally described in a `ValidationMessage` or in a `OutputUnit`. Note that since Draft 2019-09 the `format` keyword no longer generates assertions by default and instead generates only annotations unless configured otherwise using a configuration option or by using a meta-schema that uses the appropriate vocabulary. 324| Annotations | Additional information generated by a keyword for a particular input data instance. This is generally described in a `OutputUnit`. Annotation collection and reporting is turned off by default. Annotations required by keywords such as `unevaluatedProperties` or `unevaluatedItems` are always collected for evaluation purposes and cannot be disabled but will not be reported unless configured to do so. 325 326The following information is used to describe both types of results. 327 328| Type | Description 329|-------------------|------------------- 330| Evaluation Path | This is the set of keys from the root through which evaluation passes to reach the schema for evaluating the instance. This includes `$ref` and `$dynamicRef`. eg. ```/properties/bar/$ref/properties/bar-prop``` 331| Schema Location | This is the canonical IRI of the schema plus the JSON pointer fragment to the schema that was used for evaluating the instance. eg. ```https://json-schema.org/schemas/example#/$defs/bar/properties/bar-prop``` 332| Instance Location | This is the JSON pointer fragment to the instance data that was being evaluated. eg. ```/bar/bar-prop``` 333 334Assertions contains the following additional information 335 336| Type | Description 337|-------------------|------------------- 338| Message | The validation error message. 339| Code | The error code. 340| Message Key | The message key used for generating the message for localization. 341| Arguments | The arguments used for generating the message. 342| Type | The keyword that generated the message. 343| Property | The property name that caused the validation error for example for the `required` keyword. Note that this is not part of the instance location as that points to the instance node. 344| Schema Node | The `JsonNode` pointed to by the Schema Location. 345| Instance Node | The `JsonNode` pointed to by the Instance Location. 346| Details | Additional details that can be set by custom keyword validator implementations. This is not used by the library. 347 348Annotations contains the following additional information 349 350| Type | Description 351|-------------------|------------------- 352| Value | The annotation value generated 353 354 355#### Output formats 356 357This library implements the Flag, List and Hierarchical output formats defined in the [Specification for Machine-Readable Output for JSON Schema Validation and Annotation](https://github.com/json-schema-org/json-schema-spec/blob/8270653a9f59fadd2df0d789f22d486254505bbe/jsonschema-validation-output-machines.md). 358 359The List and Hierarchical output formats are particularly helpful for understanding how the system arrived at a particular result. 360 361| Output Format | Description 362|-------------------|------------------- 363| Default | Generates the list of assertions. 364| Boolean | Returns `true` if the validation is successful. Note that the fail fast option is turned on by default for this output format. 365| Flag | Returns an `OutputFlag` object with `valid` having `true` if the validation is successful. Note that the fail fast option is turned on by default for this output format. 366| List | Returns an `OutputUnit` object with `details` with a list of `OutputUnit` objects with the assertions and annotations. Note that annotations are not collected by default and it has to be enabled as it will impact performance. 367| Hierarchical | Returns an `OutputUnit` object with a hierarchy of `OutputUnit` objects for the evaluation path with the assertions and annotations. Note that annotations are not collected by default and it has to be enabled as it will impact performance. 368 369The following example shows how to generate the hierarchical output format with annotation collection and reporting turned on and format assertions turned on. 370 371```java 372JsonSchemaFactory factory = JsonSchemaFactory.getInstance(VersionFlag.V202012); 373SchemaValidatorsConfig config = new SchemaValidatorsConfig(); 374config.setPathType(PathType.JSON_POINTER); 375config.setFormatAssertionsEnabled(true); 376JsonSchema schema = factory.getSchema(SchemaLocation.of("https://json-schema.org/schemas/example"), config); 377 378OutputUnit outputUnit = schema.validate(inputData, InputFormat.JSON, OutputFormat.HIERARCHICAL, executionContext -> { 379 executionContext.getExecutionConfig().setAnnotationCollectionEnabled(true); 380 executionContext.getExecutionConfig().setAnnotationCollectionFilter(keyword -> true); 381}); 382``` 383The following is sample output from the Hierarchical format. 384 385```json 386{ 387 "valid" : false, 388 "evaluationPath" : "", 389 "schemaLocation" : "https://json-schema.org/schemas/example#", 390 "instanceLocation" : "", 391 "droppedAnnotations" : { 392 "properties" : [ "foo", "bar" ], 393 "title" : "root" 394 }, 395 "details" : [ { 396 "valid" : false, 397 "evaluationPath" : "/properties/foo/allOf/0", 398 "schemaLocation" : "https://json-schema.org/schemas/example#/properties/foo/allOf/0", 399 "instanceLocation" : "/foo", 400 "errors" : { 401 "required" : "required property 'unspecified-prop' not found" 402 } 403 }, { 404 "valid" : false, 405 "evaluationPath" : "/properties/foo/allOf/1", 406 "schemaLocation" : "https://json-schema.org/schemas/example#/properties/foo/allOf/1", 407 "instanceLocation" : "/foo", 408 "droppedAnnotations" : { 409 "properties" : [ "foo-prop" ], 410 "title" : "foo-title", 411 "additionalProperties" : [ "foo-prop", "other-prop" ] 412 }, 413 "details" : [ { 414 "valid" : false, 415 "evaluationPath" : "/properties/foo/allOf/1/properties/foo-prop", 416 "schemaLocation" : "https://json-schema.org/schemas/example#/properties/foo/allOf/1/properties/foo-prop", 417 "instanceLocation" : "/foo/foo-prop", 418 "errors" : { 419 "const" : "must be a constant value 1" 420 }, 421 "droppedAnnotations" : { 422 "title" : "foo-prop-title" 423 } 424 } ] 425 }, { 426 "valid" : false, 427 "evaluationPath" : "/properties/bar/$ref", 428 "schemaLocation" : "https://json-schema.org/schemas/example#/$defs/bar", 429 "instanceLocation" : "/bar", 430 "droppedAnnotations" : { 431 "properties" : [ "bar-prop" ], 432 "title" : "bar-title" 433 }, 434 "details" : [ { 435 "valid" : false, 436 "evaluationPath" : "/properties/bar/$ref/properties/bar-prop", 437 "schemaLocation" : "https://json-schema.org/schemas/example#/$defs/bar/properties/bar-prop", 438 "instanceLocation" : "/bar/bar-prop", 439 "errors" : { 440 "minimum" : "must have a minimum value of 10" 441 }, 442 "droppedAnnotations" : { 443 "title" : "bar-prop-title" 444 } 445 } ] 446 } ] 447} 448``` 449 450## Configuration 451 452### Execution Configuration 453 454| Name | Description | Default Value 455|--------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------- 456| `annotationCollectionEnabled` | Controls whether annotations are collected during processing. Note that collecting annotations will adversely affect performance. | `false` 457| `annotationCollectionFilter` | The predicate used to control which keyword to collect and report annotations for. This requires `annotationCollectionEnabled` to be `true`. | `keyword -> false` 458| `locale` | The locale to use for generating messages in the `ValidationMessage`. Note that this value is copied from `SchemaValidatorsConfig` for each execution. | `Locale.getDefault()` 459| `failFast` | Whether to return failure immediately when an assertion is generated. Note that this value is copied from `SchemaValidatorsConfig` for each execution but is automatically set to `true` for the Boolean and Flag output formats. | `false` 460| `formatAssertionsEnabled` | The default is to generate format assertions from Draft 4 to Draft 7 and to only generate annotations from Draft 2019-09. Setting to `true` or `false` will override the default behavior. | `null` 461 462### Schema Validators Configuration 463 464| Name | Description | Default Value 465|--------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------- 466| `pathType` | The path type to use for reporting the instance location and evaluation path. Set to `PathType.JSON_POINTER` to use JSON Pointer. | `PathType.DEFAULT` 467| `ecma262Validator` | Whether to use the ECMA 262 `joni` library to validate the `pattern` keyword. This requires the dependency to be manually added to the project or a `ClassNotFoundException` will be thrown. | `false` 468| `executionContextCustomizer` | This can be used to customize the `ExecutionContext` generated by the `JsonSchema` for each validation run. | `null` 469| `schemaIdValidator` | This is used to customize how the `$id` values are validated. Note that the default implementation allows non-empty fragments where no base IRI is specified and also allows non-absolute IRI `$id` values in the root schema. | `JsonSchemaIdValidator.DEFAULT` 470| `messageSource` | This is used to retrieve the locale specific messages. | `DefaultMessageSource.getInstance()` 471| `locale` | The locale to use for generating messages in the `ValidationMessage`. | `Locale.getDefault()` 472| `failFast` | Whether to return failure immediately when an assertion is generated. | `false` 473| `formatAssertionsEnabled` | The default is to generate format assertions from Draft 4 to Draft 7 and to only generate annotations from Draft 2019-09. Setting to `true` or `false` will override the default behavior. | `null` 474 475## Performance Considerations 476 477When the library creates a schema from the schema factory, it creates a distinct validator instance for each location on the evaluation path. This means if there are different `$ref` that reference the same schema location, different validator instances are created for each evaluation path. 478 479When the schema is created, the library will automatically preload all the validators needed and resolve references. At this point, no exceptions will be thrown if a reference cannot be resolved. If there are references that are cyclic, only the first cycle will be preloaded. If you wish to ensure that remote references can all be resolved, the `initializeValidators` method needs to be called on the `JsonSchema` which will throw an exception if there are references that cannot be resolved. 480 481The `JsonSchema` created from the factory should be cached and reused. Not reusing the `JsonSchema` means that the schema data needs to be repeated parsed with validator instances created and references resolved. 482 483Collecting annotations will adversely affect validation performance. 484 485The earlier draft specifications contain less keywords that can potentially impact performance. For instance the use of the `unevaluatedProperties` or `unevaluatedItems` keyword will trigger annotation collection in the related validators, such as the `properties` or `items` validators. 486 487This does not mean that using a schema with a later draft specification will automatically cause a performance impact. For instance, the `properties` validator will perform checks to determine if annotations need to be collected, and checks if the meta-schema contains the `unevaluatedProperties` keyword and whether the `unevaluatedProperties` keyword exists adjacent the evaluation path. 488 489 490## [Quick Start](doc/quickstart.md) 491 492## [Customizing Schema Retrieval](doc/schema-retrieval.md) 493 494## [Customizing Meta-Schemas, Vocabularies, Keywords and Formats](doc/custom-meta-schema.md) 495 496## [Validators](doc/validators.md) 497 498## [Configuration](doc/config.md) 499 500## [Specification Version](doc/specversion.md) 501 502## [YAML Validation](doc/yaml.md) 503 504## [Collector Context](doc/collector-context.md) 505 506## [JSON Schema Walkers and WalkListeners](doc/walkers.md) 507 508## [ECMA-262 Regex](doc/ecma-262.md) 509 510## [Custom Message](doc/cust-msg.md) 511 512## [Multiple Language](doc/multiple-language.md) 513 514## [MetaSchema Validation](doc/metaschema-validation.md) 515 516## [Validating RFC 3339 durations](doc/duration.md) 517 518## Projects 519 520The [light-rest-4j](https://github.com/networknt/light-rest-4j), [light-graphql-4j](https://github.com/networknt/light-graphql-4j) and [light-hybrid-4j](https://github.com/networknt/light-hybrid-4j) use this library to validate the request and response based on the specifications. If you are using other frameworks like Spring Boot, you can use the [OpenApiValidator](https://github.com/mservicetech/openapi-schema-validation), a generic OpenAPI 3.0 validator based on the OpenAPI 3.0 specification. 521 522If you have a project using this library, please submit a PR to add your project below. 523 524## Contributors 525 526Thanks 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. 527 528[@stevehu](https://github.com/sponsors/stevehu) 529 530[@prashanth-chaitanya](https://github.com/prashanth-chaitanya) 531 532[@fdutton](https://github.com/fdutton) 533 534[@valfirst](https://github.com/valfirst) 535 536[@BalloonWen](https://github.com/BalloonWen) 537 538[@jiachen1120](https://github.com/jiachen1120) 539 540[@ddobrin](https://github.com/ddobrin) 541 542[@eskabetxe](https://github.com/eskabetxe) 543 544[@ehrmann](https://github.com/ehrmann) 545 546[@prashanthjos](https://github.com/prashanthjos) 547 548[@Subhajitdas298](https://github.com/Subhajitdas298) 549 550[@FWiesner](https://github.com/FWiesner) 551 552[@rhwood](https://github.com/rhwood) 553 554[@jawaff](https://github.com/jawaff) 555 556[@nitin1891](https://github.com/nitin1891) 557 558 559For all contributors, please visit https://github.com/networknt/json-schema-validator/graphs/contributors 560 561If you are a contributor, please join the [GitHub Sponsors](https://github.com/sponsors) and switch the link to your sponsors dashboard via a PR. 562 563## Sponsors 564 565 566### Individual Sponsors 567 568 569### Corporation Sponsors 570 571 572 573