Skip to content
Derar Sattouf

Developer Tools

JSON to Zod Schema Generator

Zod schemas from JSON with optional, nullable and format checks.

  • No external services
  • Built by Derar Sattouf

JSON to Zod

Valid JSON

JSON

Zod schema

import { z } from "zod";

export const RootSchema = z.object({
  id: z.number().int(),
  email: z.email(),
  website: z.url(),
  createdAt: z.iso.datetime(),
  active: z.boolean(),
  orders: z.array(z.object({
    id: z.number().int(),
    total: z.number(),
    coupon: z.string().nullable(),
    note: z.string().optional(),
  })),
});

export type Root = z.infer<typeof RootSchema>;

Options

Guide

What is the JSON to Zod?

JSON to Zod writes a Zod validation schema from a sample JSON payload. It reads every item of every array, so keys missing from some objects become optional, null next to another type becomes nullable and mixed types become a union. It can also recognise email, URL, UUID and ISO date strings, and writes code for Zod 4 or Zod 3.

Last updated: November 2026 · Built by Derar Sattouf

How to use it

  1. 01Paste a sample JSON payload, such as an API response.
  2. 02Set the schema name and pick Zod 4 or Zod 3.
  3. 03Turn format detection, int() and strict objects on or off.
  4. 04Copy the schema into your project and review it.

Features

  • Optional keys inferred from arrays of objects
  • Nullable fields and unions for mixed types
  • Email, URL, UUID, ISO date and date-time detection
  • Zod 4 (z.email(), z.strictObject()) or Zod 3 (z.string().email(), .strict()) output
  • Exports the inferred TypeScript type with z.infer
  • Runs locally: no upload, no sign-up

See all 31 developer tools

Frequently asked questions

Is my JSON sent to a server?

No. The tool runs entirely in your browser with JavaScript, so your JSON is never sent to my server.

How does it know which fields are optional or nullable?

From the sample only. When an array holds several objects, a key that is missing from at least one of them is marked .optional(), and a field that is null in one place and a value in another is marked .nullable(). A single object gives no such evidence, so every key in it is required.

What is the difference between the Zod 4 and Zod 3 output?

Zod 4 has top-level format schemas, so the tool writes z.email(), z.url(), z.uuid(), z.iso.datetime() and z.strictObject(). For Zod 3 it writes the method form: z.string().email(), z.string().datetime() and z.object({...}).strict().

Can I use the generated schema as it is?

Treat it as a first draft. The schema describes the sample you pasted, not the API's contract: a field that happens to be a whole number becomes int(), and values the sample never shows cannot be inferred. Check it against the API documentation before relying on it.

How do I get a TypeScript type from the schema?

Keep the Export the inferred type option on. The output ends with a line such as export type Root = z.infer<typeof RootSchema>, so the type always matches the schema.