JSON to Zod

Turn a JSON sample into a Zod schema in one step. Paste an API response or config file and get z.object schemas for every nested object, with arrays of objects merged so missing fields become optional and null values become nullable — plus email, UUID, URL and date refinements and z.infer types if you want them. Copy the result into your TypeScript project. It's free, runs in your browser, and your JSON never leaves your device.

JSON to Zod mapping

JSON valueZod
"text"z.string()
42z.number().int()
4.2z.number()
truez.boolean()
null.nullable() / z.null()
[ … ]z.array(…)
{ … }z.object({ … })
missing in some items.optional()

When to use it

  1. Validate an external API's responses at runtime.
  2. Write a Zod schema for a config file or form payload quickly.
  3. Get TypeScript types and runtime validation from one source.
  4. Start a tRPC or Next.js server action input schema from example data.

How to Use

  1. Paste JSON or drop a .json file.
  2. Set the root name and options.
  3. Copy the generated schema.ts.

Features

  1. Nested object schemas
  2. Optional and nullable inference across array items
  3. int vs float
  4. Format refinements
  5. z.infer type exports
  6. .strict() option
  7. 100% client-side

FAQs

How does it decide a field is optional?

It compares every object in an array. A key that's missing from some of them is marked .optional().

Does it detect formats like email or dates?

Yes, if every value of a field matches — .email(), .uuid(), .url(), .date() or .datetime(). Turn it off for plain z.string().

Why are some numbers .int()?

When every sample value is a whole number. A single decimal anywhere makes it z.number().

Does it work with Zod 4?

Yes — the generated API (z.object, z.array, z.union, .optional, .nullable) is the same in Zod 3 and 4.

Is my JSON uploaded?

No. Conversion happens in your browser.

Technical Details

The converter infers one shape that covers the whole sample rather than reading only the first value it sees. Every object found in an array is merged: a key present in all of them becomes a required field, a key missing from some becomes .optional(), and a value that is sometimes null becomes .nullable() — the difference between a schema that validates the real API response and one that rejects the second item. Numbers are z.number().int() when every sample is a whole number and z.number() otherwise; arrays with mixed element types become a z.union; nested objects become their own named schemas declared before the schemas that use them, with names taken from the key and singularized for array items (posts → Post). Optionally, strings that all match a format are refined with .email(), .uuid(), .url(), .date() or .datetime({ offset: true }). Keys that aren't valid JavaScript identifiers are quoted, objects can be made .strict() so unknown keys fail validation, and each schema can export its z.infer type. The schema reflects the sample, so the page reminds you to check it against the real contract.

Developer Tools

Developer Tools

  • HTML Table Generator
  • Regex Cheatsheet
  • JSON to GraphQL
  • Regex Escape & Extract
  • AI Prompt Generator
  • Combine Files for AI
  • Freelance Rate Calculator
  • H-1B Wage Level Worksheet