{ }jsonkit
Format
Validate
Convert
Query
Generate

JSON to Zod schema generator

Infer a Zod v4 schema with named schemas for nested objects.
219 B · paste or drop a file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
✓ complete219 B → 398 B0.0 ms

About JSON to Zod

The JSON to Zod converter turns a sample JSON document into a Zod v4 schema. Paste an API response and get z.object schemas that validate untrusted data at runtime, plus matching TypeScript types from z.infer.

It gives TypeScript developers an accurate first draft for parsing request bodies, environment variables and third-party responses. Runs in your browser. Nothing is uploaded.

How it works

Nested named schemas

Each nested object becomes its own const XSchema = z.object({ ... }), and the parent refers to it by name. You get reusable schemas instead of one deeply nested block.

Optional-property detection

When the input has an array of objects with different keys, Optional detection adds .optional() to keys missing from some elements. This matches list data where some fields only sometimes appear.

The export keyword and inferred types

Toggle whether each schema starts with export. With export on, the tool also writes type X = z.infer<typeof XSchema> next to every schema, so you get the runtime validator and the static type together.

Type inference and its limits

Values become z.string(), z.number(), z.boolean() or z.null(). An empty array becomes z.array(z.unknown()), and a null value becomes z.null(). One example cannot show every case, so widen these by hand, for example with .nullable().

Frequently asked questions

How to convert JSON to a Zod schema?

Paste your JSON on the left and the Zod v4 schema appears on the right. Nested objects become separate named z.object schemas, and arrays are inspected to type their elements. The output includes the import { z } from "zod" line.

Which version of Zod does the output target?

Zod v4 (z.object, z.string, z.number, z.array, z.union, z.optional). The output is plain text for your own project. This tool does not bundle or run Zod, so install zod in your app.

How does it decide which properties are optional?

With optional detection on, any key missing from at least one object in an array gets .optional(). A single object gives no evidence of optional keys, so all its keys are required.

Why did a field come out as z.null() or z.unknown()?

The sample did not carry enough information. A null value can only be inferred as z.null(), and an empty array becomes z.array(z.unknown()). Use a fuller example or widen the schema by hand, for example z.string().nullable().

Is it safe to paste production JSON here?

Yes. The schema is generated in your browser and the JSON is never sent anywhere. The tool also works offline.

Sources & last verified

We checked this tool's behavior and the claims on this page against the specifications below on . The tool runs in your browser, so the output you see is exactly what the engine produced.

Found a wrong result or an outdated claim? Report an error and we will check it again.