Schema
/ API Reference / Converters
Schema
/ API Reference / Converters

toZod

A function that converts a JSON schema to a Zod schema.

The Gist

import { toZod, T_JSONSchema } from '@weser/schema'

const json: T_JSONSchema = {
  type: 'object',
  properties: {
    name: { type: 'string' },
  },
}

const schema = toZod(json)

// You can now use the schema as is
schema.safeParse({ name: 'John' })

Parameters

ParameterTypeDescription
schemaT_JSONSchemaThe JSON schema to convert to a Zod schema.

Returns

(ZodType) A Zod schema.

On this page