JSON::V...::Error(3)
π NAME π
okay so bestie, this is the manual page for JSON::V...::Error(3) from the User Contributed Perl Documentation crew, and itβs literally about JSON::Validator::Error β the JSON::Validator error object. Periodt. π
β¨ SYNOPSIS β¨
use JSON::Validator::Error;
my $err = JSON::Validator::Error->new($path, $message);
π¦ DESCRIPTION π¦
JSON::Validator::Error is a class representing validation errors from JSON::Validator. Itβs giving βerror object with main character energyβ and honestly? Obsessed. π
πΈ ATTRIBUTES πΈ
π details π
my $error = $error->details(["generic", "generic"]);
my $error = $error->details([qw(array type object)]);
my $error = $error->details([qw(format date-time Invalid)]);
my $array_ref = $error->details;
Details about the error:
- Often the category of tests that was run. Example values:
allOf,anyOf,array,const,enum,format,integer,not,null,number,object,oneOfandstring. - Often the test that failed. Example values:
additionalItems,additionalProperties,const,enum,maxItems,maxLength,maxProperties,maximum,minItems,minLength.minProperties,minimum,multipleOf,not,null,pattern,required,typeanduniqueItems, - The rest of the list contains parameters for the test that failed. It can be a plain human-readable string or numbers indicating things such as max/min values.
π message π
my $str = $error->message;
A human readable description of the error. Defaults to being being constructed from "details". See the $MESSAGES variable in the source code for more details. π
π§ͺ EXPERIMENTAL hack alert: you can localize $JSON::Validator::Error::MESSAGES to get i18n support. Example:
sub validate_i18n {
local $JSON::Validator::Error::MESSAGES = {
allOf => {type => '/allOf Forventet %3 - fikk %4.'},
};
my @error_norwegian = $jv->validate({age => 42});
}
Note that the error messages might contain a mix of English and the local language. Run some tests to see how it looks. π
π¦ path π¦
my $str = $error->path;
A JSON pointer to where the error occurred. Defaults to "/". Slay. β¨
π METHODS π
π new π
my $error = JSON::Validator::Error->new(\%attributes);
my $error = JSON::Validator::Error->new($path, \@details);
my $error = JSON::Validator::Error->new($path, \@details);
Object constructor. Iconic behavior, no notes. π
β to_string β
my $str = $error->to_string;
Returns the "path" and "message" part as a string: "$path: $message". Cute, concise, done. π«Ά
π₯ OPERATORS π₯
JSON::Validator::Error overloads the following operators:
π bool π
my $bool = !!$error;
Always true. It ate and left no crumbs. β
π stringify π
my $str = "$error";
Alias for "to_string". Same vibe, different entrance. π
π SEE ALSO π
JSON::Validator.
Source/version perl v5.42.0 + date 2025-03-17 β thatβs the footer, bestie; now go validate slayfully π
β¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-JSON-Validator 5.150.0-bp160.1.1 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms