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

toZodArray

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

The Gist

import {
  toZodArray,
  T_JSONSchemaArray,
  T_JSONSchemaString,
} from '@weser/schema'

const json: T_JSONSchemaArray<T_JSONSchemaString> = {
  type: 'array',
  items: { type: 'string' },
}

const schema = toZodArray(json)

// You can now use the schema as is
schema.safeParse(['foo', 'bar'])

Parameters

ParameterTypeDescription
schemaT_JSONSchemaArrayThe JSON array schema to convert to a Zod array schema.

Returns

(ZodArray) A Zod array schema.

On this page