JSON to Zod Schema
Paste a JSON object or array and get a Zod schema (z.object, z.string, z.array and friends) that type-checks that shape at runtime. Whole and fractional numbers both become z.number(), null becomes z.any(), empty arrays become z.array(z.any()) with the same caveats you would expect from inference. Copy it into your app to validate API payloads.
🔒 100% Client-Side & Private — processed locally in your browser. Files never leave your device.
Options
Your result will appear here
Type or paste your input above, adjust the options, then press Run. Tip: press Ctrl+Enter to run, and ? for every shortcut.
How it works
What it turns a JSON sample into
Paste one JSON value and the tool returns a TypeScript module: an import of zod, a const bound to a z.object or z.array expression built from your sample, and an export. Objects gain a z.object with a typed key per field, strings become z.string, booleans z.boolean, and both whole and fractional numbers become z.number.
A concrete reason to use it
Reach for it when you have a real API response and want runtime validation without hand-writing a schema. Paste one representative payload, and the generated schema checks every sampled field the moment you call parse in your app.
What the variable option changes
The variable name field sets the identifier the schema is bound to and exported, defaulting to schema. If several generated schemas land in one file, give each a distinct name to avoid collisions.
Where the inference stays permissive
Inference works from a sample, so edges stay loose: null becomes z.any, an empty array becomes z.array(z.any), and a mixed array uses its first non-null element. Sampled keys are required. Tighten the copy with .optional(), .nullable() or .int().
Privacy and input rules
The JSON is parsed in this tab; nothing is uploaded and the page works offline. The input must be a single JSON value, so multiple objects or trailing commas fail. A parse error reports the first problem and asks you to check quotes, commas and brackets.
Questions
What do the generated types actually guarantee?
The schema validates the shape at runtime: required keys, the correct primitive type per field, arrays of the sampled element type. Because inference works from a sample, keys present in every observed payload are required; use .optional() to soften keys that are not always present.
How are numbers handled?
Both integers and decimals map to z.number(). If you need an integer-only check, add .int() to the field — the generator deliberately stays permissive so variations in your payload do not instantly fail.
What about null, empty arrays, and mixed arrays?
A null value infers z.any() since there is no type to learn from. An empty array becomes z.array(z.any()), and a mixed array (e.g. numbers and strings) uses the first non-null element so the schema stays valid — tighten these with .nullable() or explicit unions as needed.
How do I use the output?
Paste the generated code and run the schema: const parsed = schema.parse(raw) gives you validated data, and type User = z.infer<typeof schema> gives you the inferred TypeScript type automatically.
Related tools
See categoryJSON to TypeScript
Generate TypeScript interfaces or type aliases from a JSON sample, with nested named types.
JSON to Go Struct
Generate idiomatic Go structs with json tags from a JSON sample, ready for encoding/json round-trips.
JSON to YAML
Convert JSON to YAML on your device, with a 2- or 4-space indent.
JSON to CSV
Turn a JSON array of objects into CSV, with delimiter, header, and flatten options.