.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. \*(C+ will
.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
. ds C`
. ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\"
.\" If the F register is >0, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{\
. if \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. if !\nF==2 \{\
. nr % 0
. nr F 2
. \}
. \}
.\}
.rr rF
.\" ========================================================================
.\"
.IX Title "JSON::Validator::Joi 3pm"
.TH JSON::Validator::Joi 3pm "2021-02-27" "perl v5.32.1" "User Contributed Perl Documentation"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
JSON::Validator::Joi \- Joi validation sugar for JSON::Validator
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 1
\& use JSON::Validator::Joi "joi";
\&
\& my @errors = joi\->object\->props(
\& age => joi\->integer\->min(0)\->max(200),
\& email => joi\->regex(".@.")\->required,
\& name => joi\->string\->min(1),
\& )\->validate({
\& name => "Jan Henning",
\& age => 34,
\& email => "jhthorsen@cpan.org",
\& });
\&
\& die "@errors" if @errors;
.Ve
.SS "\s-1EXPORTED FUNCTIONS\s0"
.IX Subsection "EXPORTED FUNCTIONS"
.SS "joi"
.IX Subsection "joi"
.Vb 1
\& $joi = joi(%attrs);
.Ve
.PP
Same as:
.PP
.Vb 1
\& JSON::Validator::Joi\->new(%attrs);
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
JSON::Validator::Joi is an elegant \s-1DSL\s0 schema-builder. The main purpose is
to build a \s-1JSON\s0 Schema for JSON::Validator, but
it can also validate data directly with sane defaults.
.SH "ATTRIBUTES"
.IX Header "ATTRIBUTES"
.SS "enum"
.IX Subsection "enum"
.Vb 2
\& my $joi = $joi\->enum(["foo", "bar"]);
\& my $array_ref = $joi\->enum;
.Ve
.PP
Defines a list of enum values for \*(L"integer\*(R", \*(L"number\*(R" and \*(L"string\*(R".
.SS "format"
.IX Subsection "format"
.Vb 2
\& my $joi = $joi\->format("email");
\& my $str = $joi\->format;
.Ve
.PP
Used to set the format of the \*(L"string\*(R".
See also \*(L"iso_date\*(R", \*(L"email\*(R" and \*(L"uri\*(R".
.SS "max"
.IX Subsection "max"
.Vb 2
\& my $joi = $joi\->max(10);
\& my $int = $joi\->max;
.Ve
.IP "\(bu" 2
array
.Sp
Defines the max number of items in the array.
.IP "\(bu" 2
integer, number
.Sp
Defined the max value.
.IP "\(bu" 2
object
.Sp
Defines the max number of items in the object.
.IP "\(bu" 2
string
.Sp
Defines how long the string can be.
.SS "min"
.IX Subsection "min"
.Vb 2
\& my $joi = $joi\->min(10);
\& my $int = $joi\->min;
.Ve
.IP "\(bu" 2
array
.Sp
Defines the minimum number of items in the array.
.IP "\(bu" 2
integer, number
.Sp
Defined the minimum value.
.IP "\(bu" 2
object
.Sp
Defines the minimum number of items in the object.
.IP "\(bu" 2
string
.Sp
Defines how short the string can be.
.SS "multiple_of"
.IX Subsection "multiple_of"
.Vb 2
\& my $joi = $joi\->multiple_of(3);
\& my $int = $joi\->multiple_of;
.Ve
.PP
Used by \*(L"integer\*(R" and \*(L"number\*(R" to define what the number must be a multiple
of.
.SS "regex"
.IX Subsection "regex"
.Vb 2
\& my $joi = $joi\->regex("^\ew+$");
\& my $str = $joi\->regex;
.Ve
.PP
Defines a pattern that \*(L"string\*(R" will be validated against.
.SS "type"
.IX Subsection "type"
.Vb 3
\& my $joi = $joi\->type("string");
\& my $joi = $joi\->type([qw(null integer)]);
\& my $any = $joi\->type;
.Ve
.PP
Sets the required type. This attribute is set by the convenience methods
\&\*(L"array\*(R", \*(L"integer\*(R", \*(L"object\*(R" and \*(L"string\*(R", but can be set manually if
you need to check against a list of type.
.SS "validator"
.IX Subsection "validator"
.Vb 2
\& my $joi = $joi\->validator(JSON::Validator::Schema::Draft7\->new);
\& my $jv = $joi\->validator;
.Ve
.PP
Defaults to a JSON::Validator object. This object is used by \*(L"validate\*(R".
.PP
Note: This might change to JSON::Validator::Schema::Draft7 or a later
schema in the future.
.SH "METHODS"
.IX Header "METHODS"
.SS "\s-1TO_JSON\s0"
.IX Subsection "TO_JSON"
Alias for \*(L"compile\*(R".
.SS "alphanum"
.IX Subsection "alphanum"
.Vb 1
\& my $joi = $joi\->alphanum;
.Ve
.PP
Sets \*(L"regex\*(R" to \*(L"^\ew*$\*(R".
.SS "array"
.IX Subsection "array"
.Vb 1
\& my $joi = $joi\->array;
.Ve
.PP
Sets \*(L"type\*(R" to \*(L"array\*(R".
.SS "boolean"
.IX Subsection "boolean"
.Vb 1
\& my $joi = $joi\->boolean;
.Ve
.PP
Sets \*(L"type\*(R" to \*(L"boolean\*(R".
.SS "compile"
.IX Subsection "compile"
.Vb 1
\& my $hash_ref = $joi\->compile;
.Ve
.PP
Will convert this object into a JSON-Schema data structure that
\&\*(L"schema\*(R" in JSON::Validator understands.
.SS "date_time"
.IX Subsection "date_time"
.Vb 1
\& my $joi = $joi\->date_time;
.Ve
.PP
Sets \*(L"format\*(R" to date-time.
.SS "email"
.IX Subsection "email"
.Vb 1
\& my $joi = $joi\->email;
.Ve
.PP
Sets \*(L"format\*(R" to email.
.SS "extend"
.IX Subsection "extend"
.Vb 1
\& my $new_joi = $joi\->extend($other_joi_object);
.Ve
.PP
Will extend \f(CW$joi\fR with the definitions in \f(CW$other_joi_object\fR and return a
new object.
.SS "iso_date"
.IX Subsection "iso_date"
Alias for \*(L"date_time\*(R".
.SS "integer"
.IX Subsection "integer"
.Vb 1
\& my $joi = $joi\->integer;
.Ve
.PP
Sets \*(L"type\*(R" to \*(L"integer\*(R".
.SS "items"
.IX Subsection "items"
.Vb 2
\& my $joi = $joi\->items($joi);
\& my $joi = $joi\->items([$joi, ...]);
.Ve
.PP
Defines a list of items for the \*(L"array\*(R" type.
.SS "length"
.IX Subsection "length"
.Vb 1
\& my $joi = $joi\->length(10);
.Ve
.PP
Sets both \*(L"min\*(R" and \*(L"max\*(R" to the number provided.
.SS "lowercase"
.IX Subsection "lowercase"
.Vb 1
\& my $joi = $joi\->lowercase;
.Ve
.PP
Will set \*(L"regex\*(R" to only match lower case strings.
.SS "negative"
.IX Subsection "negative"
.Vb 1
\& my $joi = $joi\->negative;
.Ve
.PP
Sets \*(L"max\*(R" to \f(CW0\fR.
.SS "number"
.IX Subsection "number"
.Vb 1
\& my $joi = $joi\->number;
.Ve
.PP
Sets \*(L"type\*(R" to \*(L"number\*(R".
.SS "object"
.IX Subsection "object"
.Vb 1
\& my $joi = $joi\->object;
.Ve
.PP
Sets \*(L"type\*(R" to \*(L"object\*(R".
.SS "pattern"
.IX Subsection "pattern"
Alias for \*(L"regex\*(R".
.SS "positive"
.IX Subsection "positive"
.Vb 1
\& my $joi = $joi\->positive;
.Ve
.PP
Sets \*(L"min\*(R" to \f(CW0\fR.
.SS "props"
.IX Subsection "props"
.Vb 1
\& my $joi = $joi\->props(name => JSON::Validator::Joi\->new\->string, ...);
.Ve
.PP
Used to define properties for an \*(L"object\*(R" type. Each key is the name of the
parameter and the values must be a JSON::Validator::Joi object.
.SS "required"
.IX Subsection "required"
.Vb 1
\& my $joi = $joi\->required;
.Ve
.PP
Marks the current property as required.
.SS "strict"
.IX Subsection "strict"
.Vb 1
\& my $joi = $joi\->strict;
.Ve
.PP
Sets \*(L"array\*(R" and \*(L"object\*(R" to not allow any more items/keys than what is defined.
.SS "string"
.IX Subsection "string"
.Vb 1
\& my $joi = $joi\->string;
.Ve
.PP
Sets \*(L"type\*(R" to \*(L"string\*(R".
.SS "token"
.IX Subsection "token"
.Vb 1
\& my $joi = $joi\->token;
.Ve
.PP
Sets \*(L"regex\*(R" to \f(CW\*(C`^[a\-zA\-Z0\-9_]+$\*(C'\fR.
.SS "validate"
.IX Subsection "validate"
.Vb 1
\& my @errors = $joi\->validate($data);
.Ve
.PP
Used to validate \f(CW$data\fR using \*(L"validate\*(R" in JSON::Validator. Returns a list of
JSON::Validator::Error objects on invalid
input.
.SS "unique"
.IX Subsection "unique"
.Vb 1
\& my $joi = $joi\->unique;
.Ve
.PP
Used to force the \*(L"array\*(R" to only contain unique items.
.SS "uppercase"
.IX Subsection "uppercase"
.Vb 1
\& my $joi = $joi\->uppercase;
.Ve
.PP
Will set \*(L"regex\*(R" to only match upper case strings.
.SS "uri"
.IX Subsection "uri"
.Vb 1
\& my $joi = $joi\->uri;
.Ve
.PP
Sets \*(L"format\*(R" to uri.
.SH "SEE ALSO"
.IX Header "SEE ALSO"
JSON::Validator
.PP
.