Skip to content

Validation modes

json-tology enforces schema constraints at two layers: the TypeScript compiler and the runtime validator. Each documented feature carries a badge that identifies which layer (or layers) catches a violation.

Badge reference

BadgeMeaning
Compile-timeThe TypeScript compiler rejects the violation. Data that fails this check never compiles - the bug is caught before the program runs.
RuntimeThe validator catches the violation when untrusted data enters the system - at instantiate, validate, is, materialize, or cast.
Compile-time + RuntimeBoth layers enforce the constraint. The compiler blocks authoring mistakes; the runtime validator guards the trust boundary for data from external sources.

Why both layers?

The two layers cover different failure modes:

  • Compile-time catches programmer mistakes - passing the wrong type to a function, violating a schema constraint in code you control.
  • Runtime catches data quality failures - untrusted input from APIs, files, user-submitted forms, or messages that may not respect the schema.

Ideal keyword coverage is Compile-time + Runtime: the compiler prevents in-process mistakes, and the runtime validator guards external boundaries.

Some constraints are Compile-time only - they express TypeScript-level invariants that have no equivalent runtime check (e.g. $id nominal brands: two schemas with the same structure but different $id values produce incompatible TypeScript types; at runtime they validate identically).

Some constraints are Runtime only - they require value inspection that happens after data arrives (e.g. cross-schema $ref resolution, uniqueness of array element values beyond tuple literal narrowing).

Where badges appear

Badges appear inline next to each documented keyword, brand, or feature in the reference pages. When a feature section covers a constraint, the badge appears at the heading or in the table entry, as shown here:

## `format` <Badge type="warning" text="Compile-time + Runtime" />

Cross-referencing

The enforcement layer for every keyword in the standard JSON Schema 2020-12 vocabulary:

KeywordLayer
typeCompile-time + Runtime
requiredCompile-time + Runtime
propertiesCompile-time + Runtime
enumCompile-time + Runtime
constCompile-time + Runtime
formatCompile-time + Runtime
patternCompile-time + Runtime
minLength / maxLengthCompile-time + Runtime
minimum / maximumCompile-time + Runtime
exclusiveMinimum / exclusiveMaximumCompile-time + Runtime
multipleOfCompile-time + Runtime
minItems / maxItemsCompile-time + Runtime
uniqueItemsCompile-time + Runtime
allOf / anyOf / oneOf / notCompile-time + Runtime
if / then / elseCompile-time + Runtime
dependentRequired / dependentSchemasCompile-time + Runtime
patternPropertiesCompile-time + Runtime
additionalProperties: falseCompile-time + Runtime
$ref (local fragment)Compile-time + Runtime
$ref (cross-schema)Compile-time + Runtime
$id nominal brandCompile-time
$schema dialect brandCompile-time
disjointWithCompile-time + Runtime
complementOfCompile-time (runtime not constraint applies via the emitted not: { $ref } wire shape; no custom registry check)
OWL property restrictions (jt:restrictions)Compile-time
OWL property characteristicsRuntime
Compose.pick / Compose.omit key validityCompile-time
Compose.discriminatedUnion discriminator presenceCompile-time
Compose.subClassOf self-subclass preventionCompile-time
Compose.equivalent self-equivalence preventionCompile-time
Compose.intersection ID collision preventionCompile-time
Transform.chain stage chain compatibilityCompile-time
Schema cross-keyword validation (ValidateSchemaType)Compile-time

Released under the MIT License.