Function lowerZodToJsonSchema

  • Converts a Zod schema instance to a plain JSON Schema object.

    Recursively descends into ZodObject shapes, ZodArray item types, ZodOptional and ZodDefault wrappers, transparently unwrapping them so the produced JSON Schema is clean and does not contain Zod-specific metadata.

    Parameters

    • schema: ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>

      Any Zod schema instance.

    Returns Record<string, unknown>

    A JSON Schema-compatible plain object.

    Example

    const jsonSchema = lowerZodToJsonSchema(z.object({ name: z.string(), age: z.number().optional() }));
    // → { type: 'object', properties: { name: { type: 'string' }, age: { type: 'number' } }, required: ['name'] }