Schema
/ API Reference / ConvertersSchema
/ API Reference / ConverterstoZod
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
Parameter | Type | Description |
---|---|---|
schema | T_JSONSchema | The JSON schema to convert to a Zod schema. |
Returns
(ZodType
) A Zod schema.
© 2024-present Robin Weser. All Rights Reserved.