NAME
std/data/json/schema/validation - JSON Schema 2020-12 evaluator.
SYNOPSIS
from std/data/json/schema/validation import JSONSchema, validate, valid;
let schema := new JSONSchema(
schema: {
type: "array",
items: { type: "integer" },
},
);
say( schema.is_valid([ 1, 2, 3 ]) );
let result := validate( { minimum: 10 }, 4 );
say( result.errors()[0].error() );
IMPLEMENTATION SUPPORT
This Pure Zuzu module is supported by all implementations of ZuzuScript. Network loading requires std/net/http through std/data/json/schema/core.
DESCRIPTION
This module contains the JSON Schema 2020-12 evaluator. It is normally used through the facade module std/data/json/schema, which re-exports the public API and the error classes.
The evaluator supports boolean schemas, object schemas, references, applicators, object and array validation, numeric and string constraints, dependent keywords, content keywords, and format validation. It validates decoded Zuzu values and uses std/data/json/schema/model to project native PairList, Set, and Bag values into the JSON data model where that is meaningful.
EXPORTS
Classes
JSONSchemaCompiled schema wrapper. Construct with
new JSONSchema( schema: ... ). Passoptionsas a named field when configuration is needed.is_valid( instance )Returns
trueorfalse. This mode stops after the first failure.validate( instance )Returns a
ValidationResultand collects independent failures asValidationErrorobjects.
Functions
valid( schema, instance, options := {} )Constructs a temporary
JSONSchemaand returnsis_valid(instance).validate( schema, instance, options := {} )Constructs a temporary
JSONSchemaand returnsvalidate(instance).
OPTIONS
options may be a Dict or PairList.
base_uriBase URI for the root schema.
registrySchemaRegistryused for references. If omitted, a new registry is created and the root schema is registered in it.loaderCallable or object with
load(uri)used to load missing referenced resources. A string result is decoded as JSON.allow_networkWhen true and
loaderis not supplied, usesHTTPResourceLoader.formatsorformat_registryFormatRegistryused forformatchecks.format_assertBoolean. Defaults to false. When false,
formatnever makes validation fail.unknown_formatDefaults to
ignore. Usefailto report unknown asserted formats.
COPYRIGHT AND LICENCE
std/data/json/schema/validation is copyright Toby Inkster.
It is free software; you may redistribute it and/or modify it under the terms of either the Artistic License 1.0 or the GNU General Public License version 2.