TXT · Text & Data tools

JSON to Zod Schema Generator

Top-level type
JSON input
Zod (TypeScript) output
Inference
Zod (TypeScript)languageJSON sampleinput0types0lines out0chars out
Go to the full JSON to Types generator with all ten languages

Shareable link

Settings are written to the URL as you change them. Nothing differs from the defaults yet.

Zod schemas from a JSON sample

Paste a JSON document and get the Zod schema that validates it, with the TypeScript type inferred from the schema exported next to it. The schema is the source of truth; the type is derived, which is the Zod convention.

Output shape

import * as z from "zod";

export const OrderSchema = z.object({
    "sku": z.string(),
    "qty": z.number(),
    "gift": z.boolean().optional(),
});
export type Order = z.infer<typeof OrderSchema>;

export const CustomerSchema = z.object({
    "id": z.number(),
    "tags": z.array(z.string()),
    "orders": z.array(OrderSchema),
});
export type Customer = z.infer<typeof CustomerSchema>;

Nested schemas come first so each reference is declared before use. Keys are quoted, so property names that are not valid identifiers work unchanged.

What the inference adds

Repeated string values become z.enum([...]). ISO 8601 strings become z.coerce.date(). Both are toggles under Inference. Turn off Integers from numeric strings when the sample has postal codes or ids as strings, or they will come out as z.number() and fail at parse time on real data.

Schema input

A pasted JSON Schema (anything with a top-level $schema) produces a Zod schema whose optionality follows the required array rather than a guess from one sample. For an API with a published schema, that is the better input.

Limits

Zod constraints that a sample cannot reveal, such as .min(), .email(), or .regex(), are not generated. Add them by hand after generation. From a JSON Schema, minimum, maxLength, and pattern are read where the renderer supports them, but not every keyword maps.

Frequently Asked Questions

One z.object() schema per distinct object shape, exported as XSchema, followed by export type X = z.infer<typeof XSchema>. Nested schemas are declared before the schemas that use them.

The generated code uses the core z.object, z.string, z.number, z.array, z.union, z.null, and .optional() calls, which are stable across Zod 3 and Zod 4. It imports with import * as z from 'zod'.

A key that is missing from some objects in an array gets .optional(). A key that is always null is typed z.null(); a key that is null in some objects and a string in others becomes z.union([z.null(), z.string()]).

Yes. Paste a schema with a top-level $schema key. Its required list decides which properties are optional, so the Zod schema is often stricter than one inferred from a sample.

The Zod renderer has no language-specific options. The Inference toggles still apply: enum inference produces z.enum([...]) and date inference produces z.coerce.date().

Generate types for one language

Full JSON to Types Generator tool

Explore Our Tools

Browse all tools