@deckyard/jsonschema
Validates a json.Value against a JSON Schema draft 2020-12 schema, and says where and why it fails. It passes every required test in the official JSON-Schema-Test-Suite; Conformance lists the exceptions.
This deck is part of Deckyard, community decks for Jennifer.
jennifer
import "@deckyard/jsonschema/" as jsonschema;
def s as jsonschema.Schema init jsonschema.compile(json.decode('{"type": "integer", "minimum": 1}'));
jsonschema.isValid($s, json.decode("3")); # true
io.printf("%s", jsonschema.describe(jsonschema.validate($s, json.decode("0"))));
# (root): must be >= 1 [/minimum]Compile a schema once and validate any number of values against it. Nothing is fetched: references resolve within the schema, to documents you register, and to the embedded 2020-12 meta-schemas.
Guides
- Validating:
validate,isValidand reading the errors - References:
$ref,$id, anchors, and registering other documents - Formats: which
formatvalues are checked, and how to turn that on - Conformance: test-suite results and known gaps
Conventions
Snippets assume this import, which tools/check-docs.sh relies on:
jennifer
import "@deckyard/jsonschema/" as jsonschema;A schema the deck cannot use throws an Error of kind jsonschema, with a message that names the place in the schema. A value that fails a schema does not throw; it comes back in the Result.