JSON to Zod Schema
Infer a Zod validation schema from any JSON sample. Paste your JSON and get a type-safe Zod schema you can copy directly into your project.
Input JSON
How it works
- Paste a JSON example representing your expected data shape.
- Click Generate Zod Schema — a ready-to-use Zod schema is produced.
- Copy the schema into your TypeScript project and use it for runtime validation.
- Click Make strict to add
.strict()and reject unknown keys.
Usage example
import { z } from 'zod';
import { userSchema } from './schemas/user';
const result = userSchema.safeParse({ name: 'Alice', id: 1 });
if (result.success) {
console.log(result.data);
} else {
console.error(result.error.format());
} About JSON to Zod Schema
Zod is a TypeScript-first schema declaration and validation library that checks your data at runtime and infers types at compile time. Because JSON carries no type information beyond its values, inferring a Zod schema from a JSON sample gives you a fast starting point instead of handwriting validators by hand. This tool performs that inference and outputs a schema you can drop straight into your project.
Use it when you receive data from an external API, a database, or an LLM and want runtime guarantees about its shape. Remember that the inferred schema is only as good as your sample: if the sample is incomplete — missing optional fields, empty arrays, or null values — the generated schema may be too narrow or too wide, so review and adjust it before relying on it in production.
Inference rules, including the string heuristics
Beyond the obvious type mapping, the generator sniffs string contents and promotes the result: a bare `YYYY-MM-DD` becomes `z.string().date()`, a value with a date and a time component becomes `z.string().datetime({ offset: true })` — the offset option is what lets a timestamp without a trailing `Z` validate — an address-shaped value becomes `.email()`, and an `http` or `https` prefix becomes `.url()`. All four are guesses from one sample value, so a field that is a URL in this record and a plain string in the next will reject the second.
Numbers become `z.number().int()` when the value is whole, so a field that is sometimes `98` and sometimes `98.5` rejects the fractional case outright — drop the `.int()` if the field is ever fractional. `null` becomes `z.null()` and its property is marked `.nullable()`, which admits null without permitting the key to be missing — add `.optional()` if absence is also legal.
How the schema is assembled
Nested objects of any depth are hoisted into their own `const XSchema` declarations, each emitted above the schema that references it, so a document nested three levels deep produces three named schemas and a root that composes them. Names come from capitalising the key and appending `Schema`; two keys that capitalise alike, such as `items` and `Items`, get a numeric suffix rather than colliding. Arrays merge their object elements the same way and become `z.array(ElementSchema)`, and heterogeneous arrays become `z.array(z.union([...]))`. An empty array becomes `z.array(z.unknown())` and an empty object becomes `z.record(z.unknown())`, both of which validate far more than the sample implies.
`Make strict` appends `.strict()` to the outermost schema only — the substitution targets the final closing parenthesis of the output — so nested object schemas keep default behaviour and will silently drop unknown keys instead of rejecting them. Toggling off removes every `.strict()` occurrence, including any you added yourself.
Where the generated schema stops
`Make strict` appends `.strict()` to the outermost schema only — the substitution targets the final closing parenthesis of the output — so nested object schemas keep default behaviour and will silently drop unknown keys instead of rejecting them. Toggling off removes every `.strict()` occurrence, including any you added yourself.
Zod is the strictest of these validators about unknown keys, which is the point of using it — a schema inferred from one sample will reject any field that sample did not contain. Loosen it with `.partial()`, `.passthrough()`, or explicit optional keys before pointing it at live traffic, or every legitimate addition upstream becomes a validation error.
Next steps
- JSON to TypeScript— complementary types
- JSON Schema Validator— test your data against the schema
Frequently Asked Questions
How do I convert JSON to a Zod schema?
Is the generated Zod schema accurate?
Is my data sent to a server?
Do I need an account or API key?
Can I use these tools offline?
All processing happens in your browser. No uploads, no tracking, no servers. Your API keys, configs, and private payloads stay private — 100% client-side.