Skip to content
This repository has been archived by the owner on May 13, 2022. It is now read-only.

talkdesk-tdx/justify

 
 

Justify

Apache 2.0 License

Justify is a JSON validator based on JSON Schema Specification and Java API for JSON Processing (JSR 374).

Key Features

  • Compliant with JSON Schema Specification Draft-07, -06, and -04.
  • Reinforces Java API for JSON Processing (JSR 374) transparently with the validation functionality.
  • Can be used with Java API for JSON Binding (JSR 367) via a custom JsonProvider.
  • Reports problems with the source locations including line and column numbers.
  • Passes all test cases provided by JSON Schema Test Suite including both mandatory and optional tests.
  • Validates the input in streaming way, which claims small memory footprint even when the input is a large JSON.
  • Accepts custom formats for string and other simple types.
  • Supports Java 8, 9, 10, 11, and 12.
  • Can be used as a modular jar in Java 9 and higher.
  • Internationalized problem messages, including Japanese language support.

Additions to the original project

Partial implementation of the AJV Extension proposal as defined here AJV with slight modifications. Currently from the AJV extensions only the string section is implemented. It allows comparison of dates, times and datetimes as string objects.

Date should be a complete date ISO 8601 (e.g. YYYY-MM-DD). Time should be in ISO 8601 (e.g. 11:13:06+00:00 or UTC 11:13:06Z). Datetime should be ISO 8601 in the form <date>T<time>.

  • formatMaximum: No change. It states that formatMaximum should be the latest date accepted, excluding the same temporal unit.
  • formatMinimum: No change: It states that formatMinimum should be the earliest date accepted, excluding the same temporal unit.
  • exclusiveFormatMaximum: Modified. This field should also be a string with a temporal unit of the above format.
  • exclusiveFormatMinimum: Modified. This field should also be a string with a temporal unit of the above format.

You may use a combination of any of the constrainsts above as they are evaluated indenpendent of each other, for instance to define a range of accepted values.

AJV Extension proposal changed to be the default option.

Getting Started

Minimum Setup

This software is available in the private TDX nexus repository and the following dependency should be added to your build. The x represents the leadpony version and y is TDX internal versioning.

Maven

<dependency>
    <groupId>org.leadpony.justify</groupId>
    <artifactId>justify</artifactId>
    <version>2.x.x.TDX.y.y</version>
</dependency>

Note that the addition of this dependency brings the following artifacts as transitive dependencies.

  • jakarta.json:jakarta.json-api
  • com.ibm.icu:icu4j

Besides the library itself, one of Java API for JSON Processing (JSR 374) implementations is needed during runtime. This library supports the following implementations and you should select Jakarta JSON Processing

Please add this dependency to your build as shown below.

Jakarta JSON Processing

Maven

<dependency>
    <groupId>org.glassfish</groupId>
    <artifactId>jakarta.json</artifactId>
    <classifier>module</classifier>
    <version>1.1.6</version>
    <scope>runtime</scope>
</dependency>

Using with the Streaming API of JSON Processing

JsonValidationService service = JsonValidationService.newInstance();

// Reads the JSON schema
JsonSchema schema = service.readSchema(Paths.get("news.schema.json"));

// Problem handler which will print problems found.
ProblemHandler handler = service.createProblemPrinter(System.out::println);

Path path = Paths.get("fake-news.json");
// Parses the JSON instance by javax.json.stream.JsonParser
try (JsonParser parser = service.createParser(path, schema, handler)) {
    while (parser.hasNext()) {
        JsonParser.Event event = parser.next();
        // Do something useful here
    }
}

Using with the Object Model API of JSON Processing

JsonValidationService service = JsonValidationService.newInstance();

// Reads the JSON schema
JsonSchema schema = service.readSchema(Paths.get("news.schema.json"));

// Problem handler which will print problems found.
ProblemHandler handler = service.createProblemPrinter(System.out::println);

Path path = Paths.get("fake-news.json");
// Reads the JSON instance by javax.json.JsonReader
try (JsonReader reader = service.createReader(path, schema, handler)) {
    JsonValue value = reader.readValue();
    // Do something useful here
}

Additional Resources

Conformance to Specification

This software is one of the most correct implementation of the JSON Schema Specification. Please refer to the result of JSON Schema Conformance Test.

Building from Source

The following tools are required to build this software.

The commands below build this software and install it into your local Maven repository.

$ git clone --recursive https://github.com/talkdesk-tdx/justify.git
$ cd justify
$ mvn clean install -P release

<<<<<<< HEAD

Release Instructions

Snapshot

Maven Snapshots are built and pushed automatically by Drone on every code merge to master branch.

Release

To create a new release execute the following command using the latest master build number from Drone (Drone CLI and authentication required):

drone build promote talkdesk-tdx/justify <latest_master_build_number> release

The command will trigger a new release using the Maven Release plugin.

origin

Copyright Notice

Copyright © 2018-2019 the Justify authors. This software is licensed under Apache License, Versions 2.0.

About

Justify is a JSON validator based on the JSON Schema specification and Java API for JSON Processing (JSR 374).

Resources

License

Apache-2.0 and 3 other licenses found

Licenses found

Apache-2.0
LICENSE
Apache-2.0
LICENSE-Addressable
MIT
LICENSE-JSON-Schema-Test-Suite
Unknown
LICENSE-json-schema.org

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%