Skip to content

Static helpers

Every operation that takes a registered schema also has a static counterpart on JsonTology. The static form builds a one-shot ephemeral registry containing only the supplied schema, runs the operation, and discards the registry.

Use static when you do not need to reuse a registry across calls.

The bookstore schemas defined in the Bookstore Domain are used in the example.

Catalogue

StaticPurposeInstance equivalent
JsonTology.is(schema, data)Boolean type guardjt.is(id, data)
JsonTology.validate(schema, data)Returns ValidationErrorsjt.validate(id, data)
JsonTology.instantiate(schema, data, options?)Validates and returns the typed valuejt.instantiate(id, data)
JsonTology.materialize(schema, partial?, options?)Fills defaults; throws on validation failurejt.materialize(schema, ...)
JsonTology.subschemaAt(schema, pointer)Resolves a sub-schema by JSON Pointerjt.subschemaAt(id, pointer)
JsonTology.dump(schema, value, options?)Serializes to wire formjt.dump(id, value)
JsonTology.dumpJson(schema, value, options?)Serializes to JSON stringjt.dumpJson(id, value)
JsonTology.toQuads(schema, data)Projects instance to ABox quadsjt.toQuads(schema, data)
JsonTology.fromQuads(schema, quads)Lifts quads back to typed objectsjt.fromQuads(id, quads)
JsonTology.toSchema(schema)Reconstructs JSON Schema from the canonical graphjt.toSchema(id)
JsonTology.toTbox(schemas)Returns OWL TBox builder for the given schemasjt.toTbox()
JsonTology.toShacl(schemas)Returns SHACL shapes builder for the given schemasjt.toShacl()
JsonTology.ontology(schemas)Returns combined TBox + SHACL builderjt.ontology()

The single-schema statics accept a schema object (not a string $id) because they need the full document to register internally. The multi-schema statics (toTbox, toShacl, ontology) accept a ReadonlyArray of schema objects.

When to pick which

  • Static. Self-contained schema, one or two operations, no shared state with other schemas.
  • Instance. Multiple schemas that $ref each other, repeated operations on the same schema, registered computed fields or invariants, format plugins, vocabulary plugins, or anything that reuses validation state.

A static call rebuilds the canonical graph for every invocation. An instance reuses the registry's compiled validators, materializer, and graph cache.

Comparison: instance vs static for validate

ts
// ── Instance form ──────────────────────────────────────────
import { bookstoreEntities as entities, CustomerSchema } from './bookstore/index.js';

const errs = entities.validate(CustomerSchema.$id, data);
// CustomerSchema is registered once at JsonTology.create() time;
// every call reuses the compiled validator.

// ── Static form ────────────────────────────────────────────
import { JsonTology, CustomerSchema } from './bookstore/index.js';

const errs2 = JsonTology.validate(CustomerSchema, data);
// Builds an ephemeral registry, registers CustomerSchema,
// runs validate, discards the registry. Each call repeats the work.

The two forms return the same ValidationErrors collection. Pick the static form for one-off scripts, examples, and self-contained schemas; pick the instance form for everything else.

See also

Released under the MIT License.