Category: Developer tools
JSON to Zod Schema Converter
Generate a Zod schema from sample JSON without uploading your data
Paste JSON and generate a Zod schema in your browser. Infer objects, arrays, strings, numbers, booleans, nullables and optional fields, then copy TypeScript-ready output. Nothing is uploaded.
import { z } from "zod";
export const userSchema = z.object({
id: z.number(),
name: z.string(),
isActive: z.boolean(),
score: z.null(),
tags: z.array(z.string()),
address: z.object({
city: z.string(),
country: z.string(),
}),
posts: z.array(z.object({
slug: z.string(),
views: z.number(),
pinned: z.boolean().optional(),
})),
});
export type User = z.infer<typeof userSchema>;
Inferred from this sample only: it can see that a field held a string, not that the string must be an email, have a minimum length or match one of a few allowed values. Treat the output as a starting point and tighten the rules yourself.
Everything on this page is processed in your browser. Nothing is uploaded.
Everything on this page is processed in your browser. Nothing is uploaded.
What this tool does
This tool reads a JSON sample locally and drafts the matching Zod object schema, including nested objects, arrays and unions. Where an array holds objects that do not agree — one element has a `pinned` flag and the next does not — the key is marked `.optional()` rather than quietly dropped, because that mismatch is usually the thing you most needed to notice. A value that was sometimes null becomes `.nullable()` instead of a two-member union. What it cannot do is invent rules it never saw: sample data shows that a field held a string, not that the string has to be an email, stay under 80 characters or be one of three allowed values. The output is a scaffold to tighten, not a finished contract.
How to use it
- Paste a representative JSON sample — the more variation it covers, the better the inference.
- Name the schema, and choose whether to include the zod import and the inferred type.
- Copy the generated code, then tighten the field rules your sample could not show.
Privacy
This tool runs entirely in your browser. Your input is never uploaded, stored or shared — closing the tab removes it.
Frequently asked questions
- Is my JSON uploaded?
- No. The JSON is parsed and the schema generated entirely in your browser tab; neither the input nor the output is sent to a server, logged or stored.
- How accurate is the inferred validation?
- It is exactly as accurate as your sample. It captures structure and types faithfully, but it cannot know constraints that structure does not express — formats, ranges, enums, or which fields are genuinely required in production. Review every field before you rely on it.
- Does it handle arrays and optional fields?
- Yes. Arrays become z.array(...), and when an array's objects have differing keys the ones that are not present everywhere are marked .optional(). A field that was sometimes null becomes .nullable().
- Can I use the output in TypeScript?
- Yes. The generated file exports the schema and, if you leave the option on, a `z.infer` type alias, so you get a validator and a matching static type from the same source.