Skip to content

pwall567/json-validation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

json-validation

Build Status License: MIT Maven Central

Validation functions for JSON Schema validation

Background

This library performs the validations required for some of the JSON Schema format validations as defined in JSON Schema Validation Section 7.3.

The functions are provided in the form of a standalone library to simplify their use in code generated from JSON Schema specification files.

Most but not all of the functions defined in the specification are included in the initial version; the remaining few may be added in due course.

Quick Start

The validations are static functions, and they all take a single parameter, the string value to be tested. They return true if the value matches the requirements of the specification (they all return false if the string is null).

date-time validation

        boolean valid = JSONValidation.isDateTime(str);

date validation

        boolean valid = JSONValidation.isDate(str);

time validation

        boolean valid = JSONValidation.isTime(str);

duration validation

        boolean valid = JSONValidation.isDuration(str);

email validation

        boolean valid = JSONValidation.isEmail(str);

hostname validation

        boolean valid = JSONValidation.isHostname(str);

uri validation

        boolean valid = JSONValidation.isURI(str);

uri-reference validation

        boolean valid = JSONValidation.isURIReference(str);

uuid validation

        boolean valid = JSONValidation.isUUID(str);

ipv4 validation

        boolean valid = JSONValidation.isIPV4(str);

ipv6 validation

        boolean valid = JSONValidation.isIPV6(str);

json-pointer validation

        boolean valid = JSONValidation.isJSONPointer(str);

relative-json-pointer validation

        boolean valid = JSONValidation.isRelativeJSONPointer(str);

regex validation

        boolean valid = JSONValidation.isRegex(str);

Additional Functions

In order to perform date validations, the library contains additional static functions related to dates. They are made public because there is little reason not to do so, and they may be useful in other contexts.

isLeapYear

This function returns true if the given year is a leap year. It takes a single integer parameter, the year to be checked. The function uses the rules of the Gregorian calendar, and while there is no limit on the input year value, the result will be meaningful only in cases where the year is subject to that calendar.

        boolean leap = JSONValidation.isLeapYear(year);

monthLength

This function returns the length of a specified month. It takes two integer parameters, the year and the month (in the range 1 to 12). As with isLeapYear, the function uses the rules of the Gregorian calendar, and the same caveat applies.

        int length = JSONValidation.isLeapYear(year, month);

No Transitive Dependencies

Importantly, the library is entirely self-contained, and the inclusion of this library in a project will not bring in a long list of transitive dependencies.

Dependency Specification

The latest version of the library is 1.5, and it may be obtained from the Maven Central repository.

Maven

    <dependency>
      <groupId>net.pwall.json</groupId>
      <artifactId>json-validation</artifactId>
      <version>1.5</version>
    </dependency>

Gradle

    implementation 'net.pwall.json:json-validation:1.5'

Gradle (kts)

    implementation("net.pwall.json:json-validation:1.5")

Peter Wall

2022-11-06

About

Validation functions for JSON Schema validation

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages