JSON to Zod Schema Converter
Paste JSON, get a ready-to-use Zod schema instantly, 100% in your browser. Correct z.number().int(), .optional() and .nullable(), plus a z.infer type. Free.
Options
What is a Zod schema?
A Zod schema is a TypeScript-first description of a value's shape that validates data at runtime and infers a static type at compile time. Generating one from a JSON sample means you never hand-write validation boilerplate for API responses, forms, or config files. This Zod schema generator infers correct types, marks absent keys as .optional(), null values as .nullable(), and hands you a z.infer type — all 100% in your browser.
Examples
API response
{"id":101,"name":"Ada Lovelace","email":"ada@example.com","active":true,"roles":["admin","user"]} import { z } from "zod";
export const RootSchema = z.object({
id: z.number().int(),
name: z.string(),
email: z.string(),
active: z.boolean(),
roles: z.array(z.string()),
});
export type Root = z.infer<typeof RootSchema>;
A typical REST payload becomes a ready-to-use Zod schema. Whole numbers infer z.number().int(), and the roles array becomes z.array(z.string()). A z.infer type comes free.
Nested object
{"repo":"zod","owner":{"login":"colinhacks","id":100}} import { z } from "zod";
export const OwnerSchema = z.object({
login: z.string(),
id: z.number().int(),
});
export const RootSchema = z.object({
repo: z.string(),
owner: OwnerSchema,
});
export type Root = z.infer<typeof RootSchema>;
Nested objects become their own named schema (OwnerSchema) and are referenced by field. Child schemas are declared before the parent that uses them, and identical shapes are declared once and reused.
Array of objects (optional field)
{"users":[{"id":1,"nick":"x"},{"id":2}]} import { z } from "zod";
export const UserSchema = z.object({
id: z.number().int(),
nick: z.string().optional(),
});
export const RootSchema = z.object({
users: z.array(UserSchema),
});
export type Root = z.infer<typeof RootSchema>;
Arrays of objects merge into one element schema. A key missing from some items becomes .optional(), so parsing still succeeds when it is absent.
Nullable field & number unification
{"items":[{"sku":"A1","discount":0.1},{"sku":"A2","discount":null}]} import { z } from "zod";
export const ItemSchema = z.object({
sku: z.string(),
discount: z.number().nullable(),
});
export const RootSchema = z.object({
items: z.array(ItemSchema),
});
export type Root = z.infer<typeof RootSchema>;
A field that is null in some samples but typed in others becomes .nullable(). Because 0.1 has a decimal point, the number unifies to z.number() rather than z.number().int().
How to convert JSON to Zod
- 1
Paste your JSON
Drop a JSON object, array, or API response into the input box. Conversion starts instantly.
- 2
Tune the output
Rename the root schema and toggle the import line, z.infer type, or export keyword to match your project's style.
- 3
Copy or download
Grab the generated Zod schema with one click and paste it straight into your validation layer.
Common Use Cases
- Validate API responses
- Turn a sample REST or GraphQL response into a Zod schema and parse it at the fetch boundary, so malformed data fails fast with a clear error instead of leaking through your app.
- Type-safe forms and inputs
- Generate a schema for form or query input and reuse the z.infer type across your UI and handlers for end-to-end type safety.
- tRPC and AI tool schemas
- Bootstrap input and output schemas for tRPC procedures or AI structured-output tools from an example payload instead of writing them by hand.
How the conversion works
- Structural inference
- Each object becomes a named schema; identical shapes are declared once and reused. Arrays of objects merge key by key, and keys absent from some items become .optional().
- Correct type mapping
- Integers map to z.number().int() and decimals to z.number(). Strings, booleans, and nulls map to z.string(), z.boolean(), and z.null(); an array of mixed primitives becomes a z.union().
- TypeScript types included
- A z.infer type alias is emitted for the root schema, so the schema stays the single source of truth and your types never drift from your validation.
- 100% client-side
- Parsing and generation run in your browser with no network calls, so your data stays private.
Tips for clean Zod schemas
- Name your root schema
- Set a meaningful root name such as User or ApiResponse instead of the default Root for readable, self-documenting code.
- Refine z.unknown() and unions
- Empty or mixed arrays produce z.unknown() or a broad z.union(). Paste a richer, representative sample so the tool infers precise types, then tighten anything that stays ambiguous.
- Validate at the boundary
- Call safeParse() where untrusted data enters — API responses, form input, webhooks — so bad data is caught before it reaches your application logic.
Frequently asked questions
How do I convert JSON to a Zod schema?
What is the difference between JSON to Zod and JSON Schema to Zod?
How do I get a TypeScript type from the schema?
How are optional and null fields handled?
What number type does it generate?
Does the output work with Zod 3 and Zod 4?
How do I validate data with the generated schema?
How are arrays and mixed types handled?
Is my JSON data private and safe?
Is the tool free? Do I need an account?
Related Tools
View all tools →Base64 Decoder & Encoder
Encoding & Formatting
Decode and encode Base64 online for free. Real-time conversion with full UTF-8 and emoji support. 100% private — runs in your browser. No signup needed.
Base64 to Image Converter
Encoding & Formatting
Decode a Base64 string or data URI back into an image in your browser. Preview, read dimensions & MIME, then download as PNG, JPG, GIF, SVG. No upload.
CSV to JSON Converter
Encoding & Formatting
Convert CSV to JSON in your browser. RFC 4180, type inference, header row, big-int safe. 100% private, no upload.
.env to JSON Converter
Encoding & Formatting
Paste a .env file, get JSON instantly. Your database passwords, API keys and tokens never leave your browser — 100% private, no upload, free dotenv parser.
Free HTML Entity Decoder — Unescape HTML
Encoding & Formatting
Decode HTML entities and unescape HTML online — free, no signup, 100% in your browser. Converts named, decimal & hex references back to characters; never uploaded.
Free HTML Entity Encoder — Escape HTML
Encoding & Formatting
Encode HTML entities and escape special characters (< > & " ') online — free, no signup, 100% in your browser. Named, decimal, or hex output; never uploaded.