---
name: "JSON::Validator::Formats"
section: "3pm"
platform: "linux"
package: "libjson-validator-perl"
version: "5.15+dfsg-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/JSON::Validator::Formats"
---

# JSON::Validator::Formats(3pm)

Functions for validating JSON schema formats

## NAME

JSON::Validator::Formats - Functions for validating 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. All functions return `"undef"` for success or an error message for failure.

## FUNCTIONS

### check\_byte

```
  my $str_or_undef = check_byte $str;
```

Checks that the string matches byte format.

### check\_date

```
  my $str_or_undef = check_date $str;
```

Validates the date part of a RFC3339 string.

### 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\_duration

```
  my $str_or_undef = check_duration $str;
```

Validate a RFC3339 duration string, such as "P3Y6M4DT12H30M5S".

### check\_double

```
  my $str_or_undef = check_double $number;
```

Tries to check if the number is a double. Note that this check is not very accurate.

### check\_email

```
  my $str_or_undef = check_email $str;
```

Validated against the RFC5322 spec.

### check\_float

```
  my $str_or_undef = check_float $number;
```

Tries to check if the number is a float. Note that this check is not very accurate.

### check\_hostname

```
  my $str_or_undef = check_hostname $str;
```

Will be validated using "is\_hostname" in Data::Validate::Domain, if installed.

### check\_idn\_email

```
  my $str_or_undef = check_idn_email $str;
```

Will validate an email with non-ASCII characters using Net::IDN::Encode if installed.

### check\_idn\_hostname

```
  my $str_or_undef = check_idn_hostname $str;
```

Will validate a hostname with non-ASCII characters using Net::IDN::Encode if installed.

### check\_int32

```
  my $str_or_undef = check_int32 $number;
```

Tries to check if the number is a int32. Note that this check is not very accurate.

### check\_int64

```
  my $str_or_undef = check_int64 $number;
```

Tries to check if the number is a int64. Note that this check is not very accurate.

### 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\_iri

```
  my $str_or_undef = check_iri $str;
```

Validate either an absolute IRI containing ASCII or non-ASCII characters, against the RFC3986 spec.

### check\_iri\_reference

```
  my $str_or_undef = check_iri_reference $str;
```

Validate either a relative or absolute IRI containing ASCII or non-ASCII characters, against the RFC3986 spec.

### check\_json\_pointer

```
  my $str_or_undef = check_json_pointer $str;
```

Validates a JSON pointer, such as "/foo/bar/42".

### check\_regex

```
  my $str_or_undef = check_regex $str;
```

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

### check\_relative\_json\_pointer

```
  my $str_or_undef = check_relative_json_pointer $str;
```

Validates a relative JSON pointer, such as "0/foo" or "3#".

### check\_time

```
  my $str_or_undef = check_time $str;
```

Validates the time and optionally the offset part of a RFC3339 string.

### check\_uri

```
  my $str_or_undef = check_uri $str;
```

Validate either a relative or absolute URI containing just ASCII characters, against the RFC3986 spec.

Note that this might change in the future to only check absolute URI.

### check\_uri\_reference

```
  my $str_or_undef = check_uri_reference $str;
```

Validate either a relative or absolute URI containing just ASCII characters, against the RFC3986 spec.

### check\_uri\_template

```
  my $str_or_undef = check_uri_reference $str;
```

Validate an absolute URI with template characters.

### check\_uuid

```
  my $str_or_undef = check_uuid $str;
```

Will check if `$str` looks like an UUID. Example UUID: "5782165B-6BB6-472F-B3DD-369D707D6C72".

## SEE ALSO

JSON::Validator.
