Skip to content
@deckyard/jsonschema

Cheatsheet

Every export of @deckyard/jsonschema. tools/check-docs.sh checks this page against the code.

jennifer
import "@deckyard/jsonschema/" as jsonschema;

Compiling

FunctionReturnsDoes
compile(schema)SchemaCompile a schema whose references stay inside it
compileWith(schema, reg)SchemaCompile a schema whose references may reach documents in reg
assertFormats(s, on)SchemaThe same schema with format asserted (true) or only annotated (false, the default)
registry()RegistryAn empty registry
register(reg, uri, schema)Registryreg with schema added under the absolute URI uri

compile and compileWith throw an Error of kind jsonschema when the schema is not an object or a boolean, and register when uri is relative.

Validating

FunctionReturnsDoes
validate(s, instance)ResultCheck a value, collecting every failure
isValid(s, instance)boolCheck a value, stopping at the first failure
describe(r)stringOne line per failure: instancePath: message [schemaPath]

Both checks throw an Error of kind jsonschema when evaluation reaches a part of the schema it cannot use: a $ref that resolves to nothing, a reference cycle, a keyword with a value of the wrong type, or a pattern RE2 cannot compile.

Types

Schema

FieldMeaning
root as json.Valuethe schema document
base as stringits base URI: its $id, or DEFAULT_BASE
registry as Registryevery resource its references can reach
formats as boolwhether format is asserted
validation as boolwhether the validation vocabulary is in force

Registry

FieldMeaning
resources as map of string to json.Valueresource URI to its root schema
anchors as map of string to stringuri#name to uri#pointer
dynamic as map of string to booluri#name of every $dynamicAnchor
meta as boolwhether the 2020-12 meta-schemas are loaded

Result

FieldMeaning
valid as boolwhether the value satisfies the schema
errors as list of Issuewhy not; empty when valid

Issue

FieldMeaning
instancePath as stringJSON Pointer to the failing value
schemaPath as stringJSON Pointer to the failing keyword, through every $ref followed
keyword as stringthe keyword that failed
message as stringwhat is wrong

Constants

ConstantValueMeaning
ERROR_KIND"jsonschema"the kind of every Error the deck throws
DEFAULT_BASE"jsonschema:/root.json"the base URI of a schema without an absolute $id