Skip to main content

Module jsonschema

Module jsonschema 

Source
Expand description

A dependency-free JSON Schema subset validator (draft 2020-12 vocabulary, the parts tool contracts and workflow schemas actually use): type (single or list, integer distinct from number), properties, required, additionalProperties (bool or schema), patternProperties (literal-prefix and ^…$ anchored-literal patterns only — no regex engine), enum, const, items (schema), prefixItems, minItems/maxItems, uniqueItems, minimum/maximum/exclusiveMinimum/exclusiveMaximum, multipleOf, minLength/maxLength, minProperties/maxProperties, allOf/anyOf/ oneOf/not, if/then/else, $ref to #/$defs/<name> / #/definitions/<name> / # (root), boolean schemas, nullable (OpenAPI sugar), default (ignored), format/pattern/description/title/ examples/$schema/$id/$comment (accepted, not enforced — pattern is checked only for the same literal shapes as patternProperties).

Errors are collected (not fail-fast) and name the JSON pointer of the offending value, so a model or an author sees every miss at once.

Functions§

check_schema
Whether schema is a well-formed schema for this validator: an object or a boolean, with known-typed keywords. Unknown keywords are allowed (JSON Schema is open); wrong-typed known keywords are reported.
explain
One-line rendering of a validation failure (for tool errors / logs).
validate
Validate value against schema. Ok(()) or every violation, each as "<pointer>: <message>" (<pointer> is /a/0/b, or / for the root).