JSON::Schema::Draft201909 - Validate data against a schema
version 0.002
use JSON::Schema::Draft201909; $js = JSON::Schema::Draft2019->new; $result = $js->evaluate($instance_data, $schema_data);
This module aims to be a fully-compliant JSON Schema evaluator and validator, targeting the currently-latest Draft 2019-09 version of the specification.
One of: flag, basic, detailed, verbose. Defaults to basic. Passed to "output_format" in JSON::Schema::Draft201909::Result.
flag
basic
detailed
verbose
When true, evaluation will immediately return upon encountering the first validation failure, rather than continuing to find all errors.
Defaults to true when output_format is flag, and false otherwise.
output_format
$result = $js->evaluate_json_string($data_as_json_string, $schema_data);
Evaluates the provided instance data against the known schema document.
The data is in the form of a JSON-encoded string (in accordance with RFC8259). The string is expected to be UTF-8 encoded.
The schema is in the form of a Perl data structure, representing a JSON Schema that respects the Draft 2019-09 meta-schema at https://json-schema.org/draft/2019-09/schema.
The result is a JSON::Schema::Draft201909::Result object, which can also be used as a boolean.
$result = $js->evaluate($instance_data, $schema_data);
The data is in the form of an unblessed nested Perl data structure representing any type that JSON allows (null, boolean, string, number, object, array).
Perl is a more loosely-typed language than JSON. This module delves into a value's internal representation in an attempt to derive the true "intended" type of the value. However, if a value is used in another context (for example, a numeric value is concatenated into a string, or a numeric string is used in an arithmetic operation), additional flags can be added onto the variable causing it to resemble the other type. This should not be an issue if data validation is occurring immediately after decoding a JSON payload, or if the JSON string itself is passed to this module.
For more information, see "MAPPING" in Cpanel::JSON::XS.
Until version 1.000 is released, this implementation is not fully specification-compliant.
The minimum extensible JSON Schema implementation requirements involve:
identifying, organizing, and linking schemas (with keywords such as $ref, $id, $schema, $anchor, $defs)
$ref
$id
$schema
$anchor
$defs
providing an interface to evaluate assertions
providing an interface to collect annotations
applying subschemas to instances and combining assertion results and annotation data accordingly.
support for all vocabularies required by the Draft 2019-09 metaschema, https://json-schema.org/draft/2019-09/schema
To date, missing components include most of these. More specifically, features to be added include:
recognition of $id
loading multiple schema documents, and registration of a schema against a canonical base URI
collection of annotations (https://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.7.7)
multiple output formats (https://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.10)
loading schema documents from disk
loading schema documents from the network
loading schema documents from a local web application (e.g. Mojolicious)
use of $recursiveRef and $recursiveAnchor
$recursiveRef
$recursiveAnchor
use of plain-name fragments with $anchor
https://json-schema.org/
RFC8259
Test::JSON::Schema::Acceptance
JSON::Validator
Bugs may be submitted through https://github.com/karenetheridge/JSON-Schema-Draft201909/issues.
I am also usually active on irc, as 'ether' at irc.perl.org and irc.freenode.org.
irc.perl.org
irc.freenode.org
Karen Etheridge <ether@cpan.org>
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.
To install JSON::Schema::Draft201909, copy and paste the appropriate command in to your terminal.
cpanm
cpanm JSON::Schema::Draft201909
CPAN shell
perl -MCPAN -e shell install JSON::Schema::Draft201909
For more information on module installation, please visit the detailed CPAN module installation guide.