JSON Schema for the enterprise
This document specifies the JSONx Validator, which offers facilities for validating JSON documents agains a JSD schema.
1 Introduction
1.1 Conventions Used in This Document
2 Purpose
3 Requirements
4 Getting Started
4.1 Valid Case
4.2 Invalid Case
5 Specification
6 Contributing
7 Special Thanks
8 License
This document presents the functionality of the JSONx Validator. It also contains a directory of links to these related resources.
The JSONx Validator consumes a JSD schema and a JSON document, and returns successfully if the specified documents are valid against the provided schema, or fails with an exception specifying the validation error if the specified document is invalid against the provided schema. The JSONx Validator utilizes the JSONx Binding Generator to perform its validation.
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC2119.
Provide a validator utility for automatic validation of JSON documents against a schema document.
-
The validator MUST be able to consume a JSON document, and validate its contents agains a provided schema document.
-
The validator MUST return successfully if a JSON document conforms to the provided schema document.
-
The validator MUST throw an exception specifying the validation error if a JSON document does not conform to the provided schema document.
The JSONx Validator provides convenience utilities for validating a JSON document agains a schema document. The following illustrates example usage of the Validator
.
The following example uses the Validator
to validate a valid JSON document against a schema document.
$ java -cp ... org.jsonx.Validator src/main/resources/example.jsd src/main/resources/valid.json
$ echo $?
0
The following example uses the Validator
to validate an invalid JSON document against a schema document.
$ java -cp ... org.jsonx.Validator src/main/resources/example.jsd src/main/resources/invalid.json
Invalid content was found in empty array: @org.jsonx.StringElement(id=0, pattern="[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"): Content is not complete
$ echo $?
1
The Validator
is a utility class that can be used on the CLI to validate a JSON document against a schema document. The Validator
class has the following usage specification:
Usage: Usage: Validator <SCHEMA> <JSON...>
Supported SCHEMA formats:
<JSD|JSDx>
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
Special thanks to EJ Technologies for providing their award winning Java Profiler (JProfiler) for development of the JSONx Framework.
This project is licensed under the MIT License - see the LICENSE.txt file for details.