std/json-schema
JSON Schema as a format, written in TorbScript: JsonSchema reads a schema of the in-place keywords of draft 2020-12
from JSON and validates a JsonValue document against it.
const schema = JsonSchema.read(text)?
const result = schema.validate(document)
for problem in result.errors {
print problem
}
One model for the versions. The model is the current draft, 2020-12; the earlier drafts will be read into it, as
ROADMAP's table of format versions says. This first step has the in-place keywords only: those that look at the value
in front of them or hand a part of it to a subschema. $ref, $dynamicRef, unevaluatedItems and
unevaluatedProperties, and a $schema of another draft, are refused with a JsonSchemaError that names them, and
so is a pattern that RE2 cannot run: a schema this package reads is a schema it checks in full.
Numbers are Float64, as in JsonValue: 1.0 is an integer, and numbers that need more than 53 bits to tell
apart are not told apart.
Modules
std/json-schema/errorThe two kinds of problemstd/json-schemareports: a schema it cannot read or refuses to read ([JsonSchemaError]), and a document that does not satisfy a schema ([Validation], made of [ValidationError]s).std/json-schema/schema[JsonSchema], the model of a schema of draft 2020-12, and the reading of it from JSON.std/json-schema/validate
Everything
- type
JsonSchemaA schema of JSON Schema draft 2020-12, as far as its in-place keywords go: [JsonSchema.read] reads one from text, [JsonSchema.parse] from a [JsonValue], and [JsonSchema.validate] answers whether a document satisfies it. - extend
JsonSchemaValidation: a schema and a document are walked together, and one [ValidationError] is collected for every keyword the document fails. - type
JsonSchemaErrorWhy a schema is not one this package reads: text that is not JSON, a keyword with a value of the wrong kind, a$schemaof another draft, a keyword of a later step of the package ($ref,$dynamicRef,unevaluatedItems,unevaluatedProperties), or apatternthat RE2 cannot run. - type
PatternSchemaOne entry ofpatternProperties: a regular expression and the schema that every property whose name it matches has to satisfy. - type
ValidationThe answer ofJsonSchema.validate: whether the document is valid and, where it is not, one [ValidationError] for every keyword it failed, in the order the schema is walked. - type
ValidationErrorOne keyword that a document failed.