Kangaroo
JSON Schema Validation Package for Java.
Kangaroo is a Java implementation for the JSON Schema Standard (draft-03
, draft-04
, draft-06
and draft-07
), that will help you validate all sorts of JSON documents, whether they are configuration files or a set of data sent to a RESTful API endpoint.
Documentation
Installation
To add a dependency using Maven, use the following:
<dependency>
<groupId>com.clivern</groupId>
<artifactId>kangaroo</artifactId>
<version>0.0.1</version>
</dependency>
To add a dependency using Gradle, use the following:
dependencies {
compile 'com.clivern:kangaroo:0.0.1'
}
To add a dependency using Scala SBT, use the following:
libraryDependencies += "com.clivern" % "kangaroo" % "0.0.1"
Usage
First import & initialize all required classes.
import com.clivern.kangaroo.util.FileReader;
import com.clivern.kangaroo.SchemaFactory;
import com.clivern.kangaroo.Validator;
FileReader fileReader = new FileReader();
SchemaFactory schemaFactory = new SchemaFactory();
Validator validator = new Validator();
Then validate the JSON
string against the JSON Schema
.
import com.clivern.kangaroo.SchemaDraft3;
// For SchemaDraft3
SchemaDraft3 schemaDraft3 = schemaFactory.unserialize(
fileReader.readFileAsString("path/to/endpoint/schema03_definition.json"),
SchemaDraft3.class
);
validator.validate(schemaDraft3, "{...JSON_DATA_HERE...}"); // returns Boolean (true || false)
validator.hasErrors(); // returns Boolean (true || false)
validator.getErrors(); // returns ArrayList<String>
import com.clivern.kangaroo.SchemaDraft4;
// For SchemaDraft4
SchemaDraft4 schemaDraft4 = schemaFactory.unserialize(
fileReader.readFileAsString("path/to/endpoint/schema04_definition.json"),
SchemaDraft4.class
);
validator.validate(schemaDraft4, "{...JSON_DATA_HERE...}"); // returns Boolean (true || false)
validator.hasErrors(); // returns Boolean (true || false)
validator.getErrors(); // returns ArrayList<String>
import com.clivern.kangaroo.SchemaDraft6;
// For SchemaDraft6
SchemaDraft6 schemaDraft6 = schemaFactory.unserialize(
fileReader.readFileAsString("path/to/endpoint/schema06_definition.json"),
SchemaDraft6.class
);
validator.validate(schemaDraft6, "{...JSON_DATA_HERE...}"); // returns Boolean (true || false)
validator.hasErrors(); // returns Boolean (true || false)
validator.getErrors(); // returns ArrayList<String>
import com.clivern.kangaroo.SchemaDraft7;
// For SchemaDraft7
SchemaDraft7 schemaDraft7 = schemaFactory.unserialize(
fileReader.readFileAsString("path/to/endpoint/schema07_definition.json"),
SchemaDraft7.class
);
validator.validate(schemaDraft7, "{...JSON_DATA_HERE...}"); // returns Boolean (true || false)
validator.hasErrors(); // returns Boolean (true || false)
validator.getErrors(); // returns ArrayList<String>
Examples
#
Versioning
For transparency into our release cycle and in striving to maintain backward compatibility, Kangaroo is maintained under the Semantic Versioning guidelines and release process is predictable and business-friendly.
See the Releases section of our GitHub project for changelogs for each release version of Kangaroo. It contains summaries of the most noteworthy changes made in each release.
Bug tracker
If you have any suggestions, bug reports, or annoyances please report them to our issue tracker at https://github.com/clivern/kangaroo/issues
Security Issues
If you discover a security vulnerability within Kangaroo, please send an email to [email protected]
Contributing
We are an open source, community-driven project so please feel free to join us. see the contributing guidelines for more details.
License
© 2019, Clivern. Released under Apache License, Version 2.0.
Kangaroo is authored and maintained by @Clivern.