Header menu logo CodecMapper

JSON Schema Support Reference

This page is easier to use if you keep the two JSON Schema features separate:

Those are related, but they are not the same workflow and they do not target the same runtime shape.

Export support from authored Schema<'T>

JsonSchema.generate exports these structural shapes directly:

These Schema features map directly:

Not exported as JSON Schema constraints

CodecMapper does not emit:

Import model for external JSON Schema

JsonSchema.import returns Schema<JsonValue>. It decodes through Schema.jsonValue first, then enforces the supported JSON Schema subset over that raw JSON DOM.

JsonSchema.importWithReport returns the imported schema plus diagnostics about:

Enforced during import:

Not enforced directly:

These keywords are reported through JsonSchema.importWithReport().FallbackKeywords. If they appear alongside supported keywords in the same schema object, the supported sibling rules still apply.

Import boundary and raw JSON fallback

Schema.jsonValue is the explicit escape hatch for imported JSON Schema shapes that do not fit the normal DSL without ambiguity.

It supports:

It is intentionally JSON-only. XML compilation fails explicitly rather than pretending there is a symmetric XML DOM contract for arbitrary JSON.

Dynamic-shape import keywords

Some receive-side JSON Schema features are supported only through the raw JsonValue import path because they describe dynamic or branch-selected shapes rather than one fixed record schema.

These include:

This is intentionally different from the normal authored Schema<'T> path:

Keep authored contracts and imported contracts separate

For contracts you own:

For contracts owned by an external schema document:

Do not treat JSON Schema import as a replacement for the normal schema DSL.

When Schema.tryMap is enough

Many JSON Schema rules are better treated as semantic refinement after structural parsing:

In those cases, parse first and refine into a stronger type. That keeps CodecMapper aligned with "parse, don't validate" while still rejecting invalid states.

When a fallback is needed

These shapes do not fit the normal Schema<'T> model directly:

Use this fallback for those cases:

For dependentSchemas and not, the importer keeps the receive path on Schema<JsonValue>, reports those keywords as fallback diagnostics, and leaves their semantics to a separate normalization or validation layer if you need them.

The common explicit-schema path should remain the fast path. Dynamic JSON fallbacks must not penalize normal record, array, and primitive codecs.

Type something to start searching.