Use TypeBox if JSON Schema is your contract: Fastify routes, OpenAPI documents, schemas you store or send to other services, or validation that has to run very fast. Use Zod if your schemas mostly live inside one TypeScript codebase and you want the richest TS-first API, transforms, and the widest support from libraries like tRPC, form tools and the AI SDK. The core difference: a TypeBox schema is a JSON Schema object that happens to infer a TypeScript type, while a Zod schema is a TypeScript object that can be converted to JSON Schema.

This comparison covers the current lines as of November 2026: TypeBox 1.4.x (now published as typebox, not @sinclair/typebox) and Zod 4.6.x. If you're also considering Valibot, see our broader Zod vs Valibot vs TypeBox comparison; this article goes deeper on the two-way choice.

TypeBox vs Zod at a glance

TypeBox 1.x Zod 4.x
npm package typebox (1.x); @sinclair/typebox is the 0.x LTS line zod (also zod/mini)
Source of truth JSON Schema objects with static type inference Zod schema objects; JSON Schema is generated
JSON Schema Native, Draft 3 through 2020-12 validation z.toJSONSchema() targeting 2020-12 (default), draft-07, draft-04, openapi-3.0
Validation engine Built-in JIT compiler (typebox/schema, typebox/compile) or any JSON Schema validator such as Ajv Zod's own parser
Transforms Type.Codec, Type.Decode, Type.Encode .transform(), .pipe(), codecs
Standard Schema Not built in; adapter example in the repo Implemented since v3.24; Standard JSON Schema since v4.2
Module format ESM only ESM and CommonJS
TypeScript 6.0 to 7.0+ for 1.x Tested against 5.5+, strict required

Versions are from the npm registry on November 17, 2026: typebox 1.4.7, zod 4.6.7.

The same schema in both libraries

Here is a realistic API payload: a UUID, an email, a bounded name, an optional non-negative integer, a two-value role and a string array.

Zod 4

import * as z from 'zod'

export const User = z.object({
  id: z.uuid(),
  email: z.email(),
  name: z.string().min(1).max(100),
  age: z.int().min(0).optional(),
  role: z.enum(['admin', 'member']),
  tags: z.array(z.string()),
})

export type User = z.infer<typeof User>

const result = User.safeParse(input)
if (!result.success) {
  console.error(z.prettifyError(result.error))
} else {
  result.data.email // string
}

const jsonSchema = z.toJSONSchema(User) // draft 2020-12 by default

TypeBox 1.x

import Type, { type Static } from 'typebox'
import { Compile } from 'typebox/compile'

export const User = Type.Object({
  id: Type.String({ format: 'uuid' }),
  email: Type.String({ format: 'email' }),
  name: Type.String({ minLength: 1, maxLength: 100 }),
  age: Type.Optional(Type.Integer({ minimum: 0 })),
  role: Type.Enum(['admin', 'member']),
  tags: Type.Array(Type.String()),
})

export type User = Static<typeof User>

const validator = Compile(User)

if (validator.Check(input)) {
  input.email // narrowed to User
} else {
  console.error(validator.Errors(input))
}

const user = validator.Parse(input) // throws on invalid input

The difference shows up in the third line of each file. In Zod, .min(1) is a method call that Zod's parser understands, and z.toJSONSchema() translates it to minLength. In TypeBox, { minLength: 1 } is the JSON Schema keyword. There's nothing to translate, so JSON.stringify(User) already gives you a schema you can hand to Ajv, an OpenAPI generator, a database or a different language's validator. You can paste either output into a JSON formatter to inspect it.

Zod's emitted schema for this object will include "additionalProperties": false because, per the Zod JSON Schema docs, z.object() does that in the default output mode, and it maps z.email() and z.uuid() to format: "email" and format: "uuid". TypeBox objects allow additional properties unless you say otherwise (Type.Object({...}, { additionalProperties: false })), which is standard JSON Schema behavior. If you migrate, check this default first.

API philosophy: JSON Schema-first vs TypeScript-first

TypeBox is a "JSON Schema Type Builder with Static Type Resolution for TypeScript," as its README puts it. Every Type.* call returns a plain JSON Schema fragment (TypeBox's metadata such as ~kind is non-enumerable, so it doesn't show up when serialized). TypeBox 1.x adds TypeScript-flavored construction on top:

  • Type.Script() parses TypeScript type syntax into schemas: Type.Script('{ x: number, y?: string }').
  • Type-level operators such as Pick, Omit, Partial, KeyOf, Conditional, Mapped and Interface evaluate to concrete JSON Schema.
  • Type.Refine() attaches custom JavaScript checks, and Type.Codec() attaches decode/encode functions.

The catch: refinements and codecs are JavaScript, so they can't go into the serialized schema. Anything that consumes the raw JSON (Ajv in another service, an OpenAPI client generator) won't see them.

Zod is TypeScript-first. The schema object is the source of truth, with a fluent API, .transform(), .pipe(), .refine(), .superRefine(), branded types and codecs. JSON Schema is an export format, and some Zod types can't be represented in it: z.date(), z.bigint(), z.map(), z.set(), z.transform(), z.custom() and a few others throw by default (unrepresentable: "any" turns them into {}). For pipes and transforms, io: "input" vs io: "output" controls which side you get. Zod also has z.fromJSONSchema(), but the docs mark it experimental and outside the stable API.

My rule of thumb: if you ever find yourself writing z.toJSONSchema() in a hot path, or committing generated JSON Schema files to the repo, your source of truth is JSON Schema and TypeBox is the more honest fit.

Validation engines and import paths in TypeBox 1.0

This is where most outdated tutorials go wrong. TypeBox 0.34 used @sinclair/typebox with TypeCompiler from @sinclair/typebox/compiler. In 1.x, per the 1.0 migration guide:

Task TypeBox 0.34 (@sinclair/typebox) TypeBox 1.x (typebox)
Build types import { Type, Static } from '@sinclair/typebox' import Type, { type Static } from 'typebox'
Compile a validator TypeCompiler.Compile(T) from /compiler, returns TypeCheck Compile(T) from typebox/compile, returns Validator
Dynamic checks Value.Check from /value Value default export from typebox/value
Custom formats FormatRegistry.Set Format.Set from typebox/format
Transforms Type.Transform Type.Codec (bi-directional), Type.Decode/Type.Encode
Recursion Type.Recursive Type.Cyclic
Kind checks T[Kind] symbol T['~kind'] or guards like Type.IsString(T)

There is one more change. The compile docs say typebox/compile is "being phased out in 1.x in favor of the more versatile typebox/schema compiler", though it stays maintained through 1.x. The newer API looks like this and accepts both TypeBox types and plain JSON Schema objects:

import Schema from 'typebox/schema'

const Vector = Schema.Compile({
  type: 'object',
  required: ['x', 'y'],
  properties: { x: { type: 'number' }, y: { type: 'number' } },
})

Vector.Check({ x: 1, y: 2 }) // true
const [ok, errors] = Vector.Errors({ x: 'nope' })

Notice that Errors returns a [boolean, errors] tuple on the typebox/schema validator but a plain array on the typebox/compile validator. That is a small trap if you switch between them. TypeBox also says the schema compiler automatically falls back to dynamic (non-JIT) validation in environments that forbid code generation, such as Cloudflare Workers.

What about performance?

I won't invent cross-library numbers. The published data points:

  • TypeBox's README benchmarks its 1.x compiler only against Ajv 8, and reports higher compile throughput across its test structures and higher validation throughput in most of them. These are the author's own benchmarks on the author's hardware.
  • Zod's v4 announcement compares Zod 4 with Zod 3: 14.71x faster string parsing, 7.43x faster arrays and 6.5x faster object safeParse, measured on Node 22.13.0 on arm64 macOS.
  • For an independent cross-library view, both projects point to community suites such as typescript-runtime-type-benchmarks and schemabenchmarks.dev.

In practice, JIT-compiled JSON Schema validators (TypeBox's compiler, Ajv) are built for high request throughput, and Zod 4 is fast enough for nearly every app that isn't validating millions of objects per second. Measure on your own payloads before letting performance decide.

Bundle size

Zod publishes its own numbers: a minimal z.boolean() script bundled with Rollup comes to 5.36 kB gzipped on Zod 4, 1.88 kB with Zod Mini, against 12.47 kB on Zod 3 (source). TypeBox doesn't publish comparable figures, so I won't guess. If bundle size decides it, build your real schemas both ways and measure.

Ecosystem fit

Integration TypeBox 1.x Zod 4
Fastify @fastify/type-provider-typebox 6.x (peer: typebox), schemas validated by Fastify's JSON Schema pipeline @fastify/type-provider-zod, requires Zod 4.2+, needs custom validator/serializer compilers
OpenAPI Schemas are already JSON Schema 2020-12, which OpenAPI 3.1 uses z.toJSONSchema(..., { target: 'openapi-3.0' }) or the Fastify provider's jsonSchemaTransform
tRPC Plain function validator; the @typeschema/typebox wrap in the tRPC docs targets 0.33 Native, plus any Standard Schema library
Hono @hono/typebox-validator 1.x (peer: typebox ^1.0.30) @hono/zod-validator or @hono/standard-validator
Elysia Built on @sinclair/typebox 0.34 (peer >=0.34 <1), not typebox 1.x yet Via Standard Schema
AI SDK tools jsonSchema() helper with a custom validate Accepted directly (Zod v3 and v4)
Forms (TanStack Form, etc.) Needs a Standard Schema adapter Native via Standard Schema

The Fastify setup shows the philosophical split well. With TypeBox the route schema is passed straight through:

import Fastify from 'fastify'
import { Type, TypeBoxTypeProvider } from '@fastify/type-provider-typebox'

const app = Fastify().withTypeProvider<TypeBoxTypeProvider>()

app.post('/users', {
  schema: { body: Type.Object({ email: Type.String({ format: 'email' }) }) },
}, async (req) => ({ email: req.body.email }))

With Zod, Fastify has to be told how to validate and serialize, because a Zod object isn't JSON Schema:

import Fastify from 'fastify'
import * as z from 'zod'
import { serializerCompiler, validatorCompiler, type ZodTypeProvider } from '@fastify/type-provider-zod'

const app = Fastify()
app.setValidatorCompiler(validatorCompiler)
app.setSerializerCompiler(serializerCompiler)

app.withTypeProvider<ZodTypeProvider>().post('/users', {
  schema: { body: z.object({ email: z.email() }) },
}, async (req) => ({ email: req.body.email }))

For LLM tool calling, the AI SDK's jsonSchema() helper takes a JSON Schema plus an optional validate function that returns { success: true, value } or { success: false, error }. TypeBox fits that directly:

import { jsonSchema, tool } from 'ai'
import Type, { type Static } from 'typebox'
import { Compile } from 'typebox/compile'

const WeatherInput = Type.Object({ city: Type.String(), unit: Type.Enum(['c', 'f']) })
const check = Compile(WeatherInput)

export const weather = tool({
  description: 'Get current weather for a city',
  inputSchema: jsonSchema<Static<typeof WeatherInput>>(WeatherInput, {
    validate: (value) =>
      check.Check(value)
        ? { success: true, value }
        : { success: false, error: new Error(JSON.stringify(check.Errors(value))) },
  }),
  execute: async ({ city, unit }) => ({ city, unit, forecast: 'sunny' }),
})

With Zod you just pass z.object(...) to inputSchema. The same reasoning applies to MCP servers, where tool input schemas are JSON Schema on the wire (see how to build an MCP server).

Standard Schema

Standard Schema is the shared ~standard interface that tRPC, TanStack Form, TanStack Router, oRPC and others accept. Zod lists it from v3.24, and Zod 4.2+ also implements the newer Standard JSON Schema interface. TypeBox 1.4.7 doesn't put ~standard on its types. Its repo ships a StandardSchema adapter example that wraps a TypeBox type, a Type.Script string or a raw JSON Schema. Copy it into your project if a library requires Standard Schema.

Decision table

Your situation Pick
Fastify API with OpenAPI docs generated from route schemas TypeBox
Schemas shared with non-TypeScript services or stored in a database TypeBox
Validation of large request volumes is a measured bottleneck TypeBox (or Ajv), after benchmarking
tRPC, Next.js server actions, React forms Zod
Heavy use of transforms, preprocessing and coercion Zod
You need CommonJS or TypeScript older than 6.0 Zod (or TypeBox 0.x LTS)
Elysia app Whatever Elysia bundles (TypeBox 0.34 today)
AI SDK tools and structured output Zod for convenience; TypeBox if you already have the JSON Schema

Migration notes

Zod → TypeBox. Map z.string().min(n) to Type.String({ minLength: n }), .optional() to Type.Optional(), z.enum([...]) to Type.Enum([...]), and .refine() to Type.Refine(). Port the meaning of .transform() and .default(), not just the syntax: transforms become Type.Decode/Type.Codec, and defaults are JSON Schema default annotations that you apply with Value.Default (or through corrective parse). Decide explicitly on additionalProperties, since Zod's emitted schemas set it to false while TypeBox leaves objects open. Expect error output to change shape: TypeBox returns JSON Schema-style errors with keyword, instancePath and message instead of Zod's issues array.

TypeBox → Zod. If you already have JSON Schema, don't hand-port it. Try z.fromJSONSchema() for a first draft, but treat the output as code to review, because the API is experimental. Then replace custom Format.Set formats with Zod refinements.

TypeBox 0.34 → 1.x. Change the package to typebox, make sure your build handles ESM-only packages (Node 22.12+ can require() most ESM, but bundlers and Jest configs may need changes), and rename TypeCompiler.Compile to Compile, Transform to Codec and Recursive to Cyclic. 1.x is developed against TypeScript 6/7, so line it up with your TypeScript 7 migration. Frameworks that pin @sinclair/typebox 0.x (Elysia today) can coexist, because 1.0 removed the symbols that used to make multiple installed versions clash.

Frequently Asked Questions

Is TypeBox faster than Zod?

TypeBox compiles schemas to JIT validators, and its README shows it beating Ajv 8 in the author's own benchmarks; Zod 4 is much faster than Zod 3 but uses a different architecture. Neither project publishes a head-to-head comparison with the other, so use the community benchmark suites or, better, your own payloads. For most APIs, validation isn't the bottleneck.

Can Zod 4 generate JSON Schema?

Yes. z.toJSONSchema(schema) targets draft 2020-12 by default and also supports draft-07, draft-04 and openapi-3.0. Types like z.date(), z.bigint() and transforms can't be represented and throw unless you pass unrepresentable: "any".

What happened to @sinclair/typebox?

It is now the 0.x LTS line for CommonJS users and older TypeScript versions. TypeBox 1.x is published as the unscoped typebox package, is ESM-only, and moved the compiler to typebox/compile (and the newer typebox/schema).

Does TypeBox support Standard Schema?

Not natively in 1.4.7. TypeBox types don't expose the ~standard property, but the repository includes a small adapter example that turns TypeBox types or JSON Schema into Standard Schema V1 objects. Zod implements Standard Schema natively.

Which is better for Fastify?

TypeBox. Fastify's validation and serialization are built on JSON Schema, so TypeBox schemas go straight in through @fastify/type-provider-typebox. Zod works well through @fastify/type-provider-zod, but it needs custom validator and serializer compilers.

Should I use TypeBox or Zod for AI tool schemas?

Use Zod if you're on the AI SDK and want the least code, since inputSchema accepts Zod schemas directly. Use TypeBox when the same schema also serves an MCP server, an OpenAPI spec or another JSON Schema consumer, and wrap it with jsonSchema() and a compiled validator.

Conclusion

The TypeBox vs Zod choice is really a question of where your contract lives. If JSON Schema is the artifact other systems read (Fastify routes, OpenAPI, stored schemas, polyglot services), TypeBox makes it the source of truth and gives you a fast compiler on top. If the contract stays inside TypeScript and you depend on tRPC, form libraries or heavy transforms, Zod 4 is the more ergonomic and better-integrated option, and z.toJSONSchema() covers the occasional export. Whichever you choose, pin the major version, and if you're on TypeBox, make sure every import uses the 1.x typebox/* paths rather than the old @sinclair/typebox ones.