xschema

Zod

Generate Zod schemas from JSON Schema definitions

The Zod adapter converts JSON Schema definitions into Zod validation schemas with full TypeScript type inference.

Overview

  • Package: @xschemadev/zod
  • Peer Dependency: zod ^3.0.0
  • Compliance: 100%

Zod is the most popular TypeScript validation library with a large ecosystem of integrations. The xschema Zod adapter generates native Zod schemas from JSON Schema with:

  • 100% compliance with JSON Schema Test Suite (all supported drafts)
  • Full type inference - generated schemas include TypeScript types
  • Runtime validation - validate data with detailed error messages

Installation

bun add @xschemadev/zod zod
npm install @xschemadev/zod zod
pnpm add @xschemadev/zod zod
yarn add @xschemadev/zod zod

Usage

user.xschema.jsonc
{
  "$schema": "https://xschema.dev/schemas/typescript.jsonc",
  "schemas": [
    {
      "id": "User",
      "adapter": "@xschemadev/zod",
      "source": "./user.schema.json"
    }
  ]
}
import {  } from "./client";

const user = ("User").({ : "1", : "Alice", : "alice@example.com" });
const user: {
    [x: string]: unknown;
    id: string;
    email: string;
    name?: string | undefined;
}

See the TypeScript guide for full setup instructions.

Supported Features

The Zod adapter has 100% compliance across all JSON Schema drafts. All tests pass.

See the Compliance page for the full breakdown by draft.

On this page