NAME

JSON::Validator::Formats - Functions for valiating JSON schema formats

SYNOPSIS

use JSON::Validator::Formats;
my $error = JSON::Validator::Formats::check_uri($str);
die $error if $error;

my $jv = JSON::Validator->new;
$jv->formats({
  "date-time"     => JSON::Validator::Formats->can("check_date_time"),
  "email"         => JSON::Validator::Formats->can("check_email"),
  "hostname"      => JSON::Validator::Formats->can("check_hostname"),
  "ipv4"          => JSON::Validator::Formats->can("check_ipv4"),
  "ipv6"          => JSON::Validator::Formats->can("check_ipv6"),
  "regex"         => JSON::Validator::Formats->can("check_regex"),
  "uri"           => JSON::Validator::Formats->can("check_uri"),
  "uri-reference" => JSON::Validator::Formats->can("check_uri_reference"),
});

DESCRIPTION

JSON::Validator::Formats is a module with utility functions used by "formats" in JSON::Validator to match JSON Schema formats.

FUNCTIONS

check_date_time

my $str_or_undef = check_date_time $str;

Validated against RFC3339 timestamp in UTC time. This is formatted as "YYYY-MM-DDThh:mm:ss.fffZ". The milliseconds portion (".fff") is optional

check_email

my $str_or_undef = check_email $str;

Validated against the RFC5322 spec.

check_hostname

my $str_or_undef = check_hostname $str;

Will be validated using "is_hostname" in Data::Validate::Domain, if installed.

check_ipv4

my $str_or_undef = check_ipv4 $str;

Will be validated using "is_ipv4" in Data::Validate::IP, if installed or fall back to a plain IPv4 IP regex.

check_ipv6

my $str_or_undef = check_ipv6 $str;

Will be validated using "is_ipv6" in Data::Validate::IP, if installed.

check_regex

my $str_or_undef = check_regex $str;

Will check if the string is a regex, using qr{...}.

check_uri

my $str_or_undef = check_uri $str;

Validated against the RFC3986 spec.

check_uri_reference

my $str_or_undef = check_uri_reference $str;

SEE ALSO

JSON::Validator.