Schema

Transformation

We can transform schema into various formats, including other other libraries and JSON schema.

For out-of-the-box library support, view the Library Support page.

If you're looking to implement custom parsers and formatters, keep reading these docs.

Given the nature and complexity of schema/validation libraries, conversions tend to be a somewhat lossy process, meaning perfect transformations are not always possible.

Parser

Parsers convert a schema into an abstract "schema def". This is somewhat similar to JSON schema, but simpler and easier to work with.

const parser = createParser(MyCustomParser);
 
// or, e.g.
const parser = createParser(ZodParser());
 
const schemaDef = parser.parse(Schema);

Formatter

Formatters are used to convert schema defs into another form. For example, given a schema def, a zod formatter would convert the def into usable zod schema.

const formatter = createFormatter(ZodFormatter);
 
const zodSchema = formatter.format(schemaDef);
zodSchema.parse(value);

Discriminator

Discriminators are used determine if a schema is of a particular library.

const isZodSchema = ZodDiscriminator().isSchema(maybeZodSchema);

On this page