1JSON::Validator::FormatUss(e3r)Contributed Perl DocumentJaStOiNo:n:Validator::Formats(3)
2
3
4
6 JSON::Validator::Formats - Functions for validating JSON schema formats
7
9 use JSON::Validator::Formats;
10 my $error = JSON::Validator::Formats::check_uri($str);
11 die $error if $error;
12
13 my $jv = JSON::Validator->new;
14 $jv->formats({
15 "date-time" => JSON::Validator::Formats->can("check_date_time"),
16 "email" => JSON::Validator::Formats->can("check_email"),
17 "hostname" => JSON::Validator::Formats->can("check_hostname"),
18 "ipv4" => JSON::Validator::Formats->can("check_ipv4"),
19 "ipv6" => JSON::Validator::Formats->can("check_ipv6"),
20 "regex" => JSON::Validator::Formats->can("check_regex"),
21 "uri" => JSON::Validator::Formats->can("check_uri"),
22 "uri-reference" => JSON::Validator::Formats->can("check_uri_reference"),
23 });
24
26 JSON::Validator::Formats is a module with utility functions used by
27 "formats" in JSON::Validator to match JSON Schema formats. All
28 functions return "undef" for success or an error message for failure.
29
31 check_byte
32 my $str_or_undef = check_byte $str;
33
34 Checks that the string matches byte format.
35
36 check_date
37 my $str_or_undef = check_date $str;
38
39 Validates the date part of a RFC3339 string.
40
41 check_date_time
42 my $str_or_undef = check_date_time $str;
43
44 Validated against RFC3339 timestamp in UTC time. This is formatted as
45 "YYYY-MM-DDThh:mm:ss.fffZ". The milliseconds portion (".fff") is
46 optional
47
48 check_duration
49 my $str_or_undef = check_duration $str;
50
51 Validate a RFC3339 duration string, such as "P3Y6M4DT12H30M5S".
52
53 check_double
54 my $str_or_undef = check_double $number;
55
56 Tries to check if the number is a double. Note that this check is not
57 very accurate.
58
59 check_email
60 my $str_or_undef = check_email $str;
61
62 Validated against the RFC5322 spec.
63
64 check_float
65 my $str_or_undef = check_float $number;
66
67 Tries to check if the number is a float. Note that this check is not
68 very accurate.
69
70 check_hostname
71 my $str_or_undef = check_hostname $str;
72
73 Will be validated using "is_hostname" in Data::Validate::Domain, if
74 installed.
75
76 check_idn_email
77 my $str_or_undef = check_idn_email $str;
78
79 Will validate an email with non-ASCII characters using Net::IDN::Encode
80 if installed.
81
82 check_idn_hostname
83 my $str_or_undef = check_idn_hostname $str;
84
85 Will validate a hostname with non-ASCII characters using
86 Net::IDN::Encode if installed.
87
88 check_int32
89 my $str_or_undef = check_int32 $number;
90
91 Tries to check if the number is a int32. Note that this check is not
92 very accurate.
93
94 check_int64
95 my $str_or_undef = check_int64 $number;
96
97 Tries to check if the number is a int64. Note that this check is not
98 very accurate.
99
100 check_ipv4
101 my $str_or_undef = check_ipv4 $str;
102
103 Will be validated using "is_ipv4" in Data::Validate::IP, if installed
104 or fall back to a plain IPv4 IP regex.
105
106 check_ipv6
107 my $str_or_undef = check_ipv6 $str;
108
109 Will be validated using "is_ipv6" in Data::Validate::IP, if installed.
110
111 check_iri
112 my $str_or_undef = check_iri $str;
113
114 Validate either an absolute IRI containing ASCII or non-ASCII
115 characters, against the RFC3986 spec.
116
117 check_iri_reference
118 my $str_or_undef = check_iri_reference $str;
119
120 Validate either a relative or absolute IRI containing ASCII or non-
121 ASCII characters, against the RFC3986 spec.
122
123 check_json_pointer
124 my $str_or_undef = check_json_pointer $str;
125
126 Validates a JSON pointer, such as "/foo/bar/42".
127
128 check_regex
129 my $str_or_undef = check_regex $str;
130
131 Will check if the string is a regex, using "qr{...}".
132
133 check_relative_json_pointer
134 my $str_or_undef = check_relative_json_pointer $str;
135
136 Validates a relative JSON pointer, such as "0/foo" or "3#".
137
138 check_time
139 my $str_or_undef = check_time $str;
140
141 Validates the time and optionally the offset part of a RFC3339 string.
142
143 check_uri
144 my $str_or_undef = check_uri $str;
145
146 Validate either a relative or absolute URI containing just ASCII
147 characters, against the RFC3986 spec.
148
149 Note that this might change in the future to only check absolute URI.
150
151 check_uri_reference
152 my $str_or_undef = check_uri_reference $str;
153
154 Validate either a relative or absolute URI containing just ASCII
155 characters, against the RFC3986 spec.
156
157 check_uri_template
158 my $str_or_undef = check_uri_reference $str;
159
160 Validate an absolute URI with template characters.
161
162 check_uuid
163 my $str_or_undef = check_uuid $str;
164
165 Will check if $str looks like an UUID. Example UUID:
166 "5782165B-6BB6-472F-B3DD-369D707D6C72".
167
169 JSON::Validator.
170
171
172
173perl v5.34.0 2021-07-22 JSON::Validator::Formats(3)