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

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

Frequently Asked Questions

How do I convert JSON to a Zod schema?
Paste a JSON sample into the input and click Infer Schema. The tool analyses the structure, data types, and nested objects, then generates a TypeScript Zod schema you can copy and use in your project. Optional fields are inferred from null values.
Is the generated Zod schema accurate?
The schema infers types from your sample data. For optional fields, empty arrays, and null values the tool marks them as optional or nullable. For precise type inference, provide a representative JSON sample that covers all fields you want validated.
Is my data sent to a server?
No. Every tool on jsonversal runs entirely in your browser using the Web Crypto API, File API, and Clipboard API. Nothing is ever uploaded — not even the JSON you paste in.
Do I need an account or API key?
No signup, no email, no API key. All tools are free to use with no signup required.
Can I use these tools offline?
Yes. Once the page loads, all tools work offline. There are no external API calls or CDN dependencies at runtime.
🔒
Your data never leaves your device

All processing happens in your browser. No uploads, no tracking, no servers. Your API keys, configs, and private payloads stay private — 100% client-side.

esc
↑↓ navigate ↵ open esc close