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