1JSON::Validator::Error(U3s)er Contributed Perl DocumentatJiSoOnN::Validator::Error(3)
2
3
4

NAME

6       JSON::Validator::Error - JSON::Validator error object
7

SYNOPSIS

9         use JSON::Validator::Error;
10         my $err = JSON::Validator::Error->new($path, $message);
11

DESCRIPTION

13       JSON::Validator::Error is a class representing validation errors from
14       JSON::Validator.
15

ATTRIBUTES

17   details
18         my $error     = $error->details(["generic", "generic"]);
19         my $error     = $error->details([qw(array type object)]);
20         my $error     = $error->details([qw(format date-time Invalid)]);
21         my $array_ref = $error->details;
22
23       Details about the error:
24
25       1.
26         Often the category of tests that was run. Example values: allOf,
27         anyOf, array, const, enum, format, integer, not, null, number,
28         object, oneOf and string.
29
30       2.
31         Often the test that failed. Example values: additionalItems,
32         additionalProperties, const, enum, maxItems, maxLength,
33         maxProperties, maximum, minItems, minLength.  minProperties, minimum,
34         multipleOf, not, null, pattern, required, type and uniqueItems,
35
36       3.
37         The rest of the list contains parameters for the test that failed. It
38         can be a plain human-readable string or numbers indicating things
39         such as max/min values.
40
41   message
42         my $str = $error->message;
43
44       A human readable description of the error. Defaults to being being
45       constructed from "details". See the $MESSAGES variable in the source
46       code for more details.
47
48       As an EXPERIMENTAL hack you can localize
49       $JSON::Validator::Error::MESSAGES to get i18n support. Example:
50
51         sub validate_i18n {
52           local $JSON::Validator::Error::MESSAGES = {
53             allOf => {type => '/allOf Forventet %3 - fikk %4.'},
54           };
55
56           my @error_norwegian = $jv->validate({age => 42});
57         }
58
59       Note that the error messages might contain a mix of English and the
60       local language. Run some tests to see how it looks.
61
62   path
63         my $str = $error->path;
64
65       A JSON pointer to where the error occurred. Defaults to "/".
66

METHODS

68   new
69         my $error = JSON::Validator::Error->new(\%attributes);
70         my $error = JSON::Validator::Error->new($path, \@details);
71         my $error = JSON::Validator::Error->new($path, \@details);
72
73       Object constructor.
74
75   to_string
76         my $str = $error->to_string;
77
78       Returns the "path" and "message" part as a string: "$path: $message".
79

OPERATORS

81       JSON::Validator::Error overloads the following operators:
82
83   bool
84         my $bool = !!$error;
85
86       Always true.
87
88   stringify
89         my $str = "$error";
90
91       Alias for "to_string".
92

SEE ALSO

94       JSON::Validator.
95
96
97
98perl v5.36.0                      2023-01-20         JSON::Validator::Error(3)
Impressum