JSON::...Result(3pm)
β¨ NAME β¨
JSON::Schema::Modern::Result β bestie, this is the lil container that holds the result of a JSON Schema evaluation π
So like, when you run a schema against your data and you're like "did it pass?? what went wrong??" β this object is what slides into your DMs with the receipts.
πΈ VERSION πΈ
version 0.642
I use a linearly-increasing version numbering scheme. No meaning should be presumed or inferred from the version being less than 1.0.
(translation: don't come for me about the 0.642 thing, the number is just a number, it's not a vibe check on maturity, ok?? π)
π SYNOPSIS π
use JSON::Schema::Modern;
my $js = JSON::Schema::Modern->new;
my $result = $js->evaluate($data, $schema);
my @errors = $result->errors;
my $result_data_encoded = encode_json($result); # calls TO_JSON
# use in numeric and boolean context
say sprintf('got %d %ss', $result, ($result->valid ? 'annotation' : 'error'));
# use in string context
say 'full results: ', $result;
# combine two results into one:
my $overall_result = $result1 & $result2;
π¦ DESCRIPTION π¦
This object holds the complete results of evaluating a data payload against a JSON Schema using JSON::Schema::Modern. It's the whole shebang, no crumbs left behind. π
π OVERLOADS π
The object contains a string overload, which evaluates to a potentially multi-line string summarizing the errors within (if any); this is intended to be used as a user-oriented error message that references data locations, but not schema locations. So it's the "hey bestie, something's off and here's roughly where" version, not the "here's the exact schema path, go read the spec" version.
The object also contains a bitwise AND overload (&), for combining two results into one β the result is valid iff both inputs are valid; annotations and errors from the second argument are appended to those of the first in a new Result object. Two results, one object, they ate and left no crumbs. π«Ά
π CONSTRUCTOR ARGUMENTS π
Unless otherwise noted, these are also available as read-only accessors.
valid
A boolean. Indicates whether validation was successful or failed. β¨
Optional, as it can be calculated from the presence of errors or annotations. (so like, if you're lazy, the object can figure it out itself, no cap)
errors
An array of JSON::Schema::Modern::Error objects. π
annotations
An array of JSON::Schema::Modern::Annotation objects. πΈ
output_format
Also available as a read/write accessor.
One of: flag, basic, strict_basic, terse, data_only. Defaults to basic.
flagreturns just the result of the evaluation: either{"valid": true}or{"valid": false}. Absolute bare minimum, it's giving minimalism. πbasicadds the list oferrorsorannotationsto the boolean evaluation result.instance_locationandkeyword_locationare always included, as JSON pointers, describing the path to the evaluation location;absolute_keyword_locationis added (as a resolved URI) whenever it is known and different fromkeyword_location.strict_basicis likebasicbut follows the draft-2019-09 specification precisely, including replicating an error fixed in the next draft, in thatinstance_locationandkeyword_locationvalues are provided as fragment-only URI references rather than JSON pointers. (yes bestie, we're faithfully reproducing a bug on purpose, the spec said so π)terseis not described in any specification; it is likebasic, but omits some redundant errors (for example the one for theallOfkeyword that is added when any of the subschemas underallOffailed evaluation). Less yapping, same tea. πdata_onlyreturns a string, not a data structure: it contains a list of errors identified only by theirinstance_locationand error message (orkeyword_location, when the error occurred while loading the schema itself). This format is suitable for generating errors when the schema is not published, or for describing errors with the schema itself. This is not an official specification format and may change slightly over time, as it is tested in production environments. (so like, it's the experimental fit, it might get a glow-up later, don't build your whole personality on it being frozen π)
formatted_annotations
A boolean flag indicating whether format should include annotations in the output. Defaults to true. β
exception
Indicates that evaluation stopped due to a severe error. Like the whole thing face-planted. π
recommended_response
A tuple, consisting of [ integer, string ], indicating the recommended HTTP response code and string to use for this result (if validating an HTTP request). This could exist for things like a failed authentication check in OpenAPI validation, in which case it would contain [ 401, 'Unauthorized' ]. Slay, it tells you exactly what to send back. π₯
Only populated when there are errors; when not explicitly set by an evaluator, defaults to [ 500, 'Internal Server Error' ] if any errors indicate an exception, and [ 400, <first error string> ] otherwise. The exact error string is hidden in the case of 500 errors because you should not leak internal issues with your application, but you may also wish to obfuscate normal validation errors, in which case you should check for 400 and change the string to 'Bad Request'.
bestie, keep your internals private, that's the whole point of the 500 hiding ok π
Also available as a read/write accessor.
defaults
A hashref, mapping json pointer locations in the instance data to the default value assigned to the property at this location, taken from default keywords in the schema under properties and patternProperties keywords (requires the defaults in JSON::Schema::Modern configuration to be enabled). This data will also be included in the basic output format when it is defined. π
data
Contains a cloned copy of the instance data that was evaluated; includes decoded values from contentEncoding and contentMediaType keywords, and is also populated with defaults if defaults is set (via with_defaults in JSON::Schema::Modern).
In results coming from OpenAPI::Modern, this value may contain deserialized data from various parts of the HTTP message, such as path and query parameters, header values, and the deserialized message body. Refer to that documentation for more details. π¦
β METHODS β
format
Returns a data structure suitable for serialization; requires one argument specifying the output format to use, which corresponds to the formats documented in <https://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.10.4>. The only supported formats at this time are flag, basic, strict_basic, and terse.
TO_JSON
Calls format with the style configured in output_format. She does what she's told. π
count
Returns the number of annotations when the result is true, or the number of errors when the result is false. One number, two moods. π
combine
When provided with another result object, returns a new object with the combination of all results. See & at OVERLOADS. π«Ά
dump
Returns a JSON string representing the result object, using the requested format, according to the draft2019-09 specification <https://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.10> and the draft2020-12 specification <https://json-schema.org/draft/2020-12/json-schema-core#section-12>.
π§ SERIALIZATION π§
Results (and their contained errors and annotations) can be serialized in a number of ways. Pick your fighter bestie π
Results have defined output_formats, which can be generated as nested unblessed hashes/arrays and are suitable for serializing using a JSON encoder for use in another application. A JSON string of the result can be obtained directly using dump. β¨
If it is preferable to omit direct references to the schema (for example in an application where the schema is not published), but still convey some semantic information about the nature of the errors, stringify the object directly. This also means that result objects can be thrown as exceptions, or embedded in error messages. π€
If you are embedding the full result inside another data structure, perhaps to be serialized to JSON (or another format) later on, use TO_JSON or format. π
π GIVING THANKS π
If you found this module to be useful, please show your appreciation by adding a +1 in MetaCPAN <https://metacpan.org/dist/JSON-Schema-Modern> and a star in GitHub <https://github.com/karenetheridge/JSON-Schema-Modern>. Honestly it costs zero dollars and it makes someone's whole week, do it. β
πΈ SUPPORT πΈ
Bugs may be submitted through <https://github.com/karenetheridge/JSON-Schema-Modern/issues>.
I am also usually active on irc, as 'ether' at irc.perl.org and irc.libera.chat.
You can also find me on the JSON Schema Slack server <https://json-schema.slack.com> and OpenAPI Slack server <https://open-api.slack.com>, which are also great resources for finding help. Come say hi, the group chat is open π«Ά
π AUTHOR π
Karen Etheridge <ether@cpan.org>
π COPYRIGHT AND LICENCE π
This software is copyright (c) 2020 by Karen Etheridge.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
Some schema files have their own licence, in share/LICENSE. (yes babe, check before you redistribute, that's the rule π
)
okay that's the whole page β perl v5.40.1, dated 2026-07-31, and this was JSON::Schema::Modern::Result(3pm) π go forth and validate, bestie, you're gonna slay πβ¨
π¦ where this page comes from
- ubuntu stonking: libjson-schema-modern-perl 0.642-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms