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

toZodObject

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

The Gist

import { toZodObject, T_JSONSchemaObject } from '@weser/schema'

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

const schema = toZodObject(json)

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

Parameters

ParameterTypeDescription
schemaT_JSONSchemaObjectThe JSON object schema to convert to a Zod object schema.

Returns

(ZodObject) A Zod object schema.

On this page