Zero Signup ToolsFree browser tools

Developer Tools

JSON to Zod Schema Converter

Paste a JSON sample and get a Zod schema with inferred types, optional fields, detected formats (email, URL, UUID, ISO date), and a TypeScript type.

0 chars

Output options

Indent

Inference options

How the inferrer maps JSON to Zod

"hello"

z.string()

Plain string

"ada@example.com"

z.string().email()

Detected with format on

42

z.number().int()

Integer detected

3.14

z.number()

Non-integer number

true

z.boolean()

Boolean

null

z.null()

Merges with siblings as .nullable()

[]

z.array(z.unknown())

Empty array has no element info

[1, 2, 3]

z.array(z.number().int())

Homogeneous array

[1, "two"]

z.array(z.union([z.number().int(), z.string()]))

Mixed array becomes a union

How to use

  1. Paste a JSON sample into the input on the left, or click Load object sample or Load array of samples to see worked examples.
  2. Read the generated Zod schema on the right. Object keys keep their original names, nested objects nest with z.object, and arrays use z.array with one inferred element schema.
  3. Set the variable name and indent. The (Pascal-cased) variable name is also used for the appended type declaration.
  4. Toggle Treat root array as samples to merge per-item shapes when the input is an array of objects, Detect string formats to promote email, URL, UUID, ISO date, and IPv4 strings, and Mark whole numbers as integers to emit z.number().int() for whole values.
  5. Toggle Use strict objects to add .strict() to every z.object, Include z.infer type for the appended type alias, then click Copy schema to paste the output into a .ts file.

About this tool

JSON to Zod Schema Converter takes a JSON sample (an object, an array of objects, or any value) and emits the matching Zod schema in your browser. The native JSON parser reads the input, the inferrer walks the value tree, and the emitter prints a clean import + const + inferred TypeScript type that you can paste into a .ts file. Primitives map to z.string(), z.number() (with z.number().int() when the value is a whole number), z.boolean(), and z.null(). Arrays infer one merged element schema across every item, so [1, 2, 3] becomes z.array(z.number().int()) while [1, "two"] becomes z.array(z.union([z.number().int(), z.string()])). Objects infer one field at a time. When the input is an array of objects and the Treat root array as samples toggle is on, the inferrer merges field shapes across all items: fields that exist in some samples but not others become .optional(), and fields whose values vary in type become unions. null values mixed with another type become .nullable(). When Detect string formats is on, strings that match an unambiguous pattern are promoted to .email(), .url(), .uuid(), .datetime() (RFC 3339), .date() (YYYY-MM-DD), or .ip({ version: "v4" }), so the schema captures the format intent without changing the JavaScript shape. Output options let you set the variable name, switch to a 4-space indent, mark every z.object call .strict() to reject unknown keys, include or hide the import line, export the schema and the inferred type, and append type X = z.infer<typeof X>. Useful for typing API responses you have a sample for, scaffolding a Zod schema from a fixture file, or starting a runtime-validated form schema from a JSON payload. Parsing and code generation run locally, so the JSON you paste here never leaves your browser.

Free to use. Works in your browser. No signup, no login.

Related tools

You may also like

All tools
All toolsDeveloper Tools