JSON to Zod

Infer Zod schemas from JSON.

FreeNo accountOn your device

Runs in your browser. How to verify

Loading tool…

About this tool

Paste a JSON sample and get a ready-to-use Zod schema plus the inferred TypeScript type. Whole numbers become z.number().int(), decimals become z.number(), and nested objects and arrays are mapped recursively.

How to use

1
Step 1
Paste a sample JSON object.
2
Step 2
Press Run.
3
Step 3
Copy the code, then rename the schema and add.optional() or.nullable() where the real data needs them.

How it works

The sample is converted to a schema: string to z.string(), integer to z.number().int(), decimal to z.number(), boolean to z.boolean(), null to z.null(), arrays to z.array() of the merged item type and objects to z.object(). The output includes the zod import, an exported schema named toolSchema and a type exported with z.infer.

Worked example

A product record

Input
{"id":1,"name":"Ada","tags":["a"],"price":9.5}
Output
import { z } from "zod" export const toolSchema = z.object({ id: z.number().int(), name: z.string(), tags: z.array(z.string()), price: z.number() }) export type tool = z.infer<typeof toolSchema>
Walkthrough
1 is an integer so it gets.int(), while 9.5 is a plain z.number().

Limitations

  • Fields missing from some array items get.optional() and mixed item types become z.union, but nothing is marked.nullable() and no enums are inferred.
  • An empty array becomes z.array(z.unknown()).
  • A sample value like 1.0 is read as the integer 1 by the JSON parser.
  • No string formats such as.email() or.url() are guessed.

Questions

How do I create a Zod schema from JSON?
Paste a sample object and press Run. The tool outputs a z.object schema and a z.infer type.
Does it add.optional() for missing fields?
No. It only sees one sample, so all keys are required. Add.optional() by hand.
Why is my number marked.int()?
The sample value had no fractional part. Remove.int() if the field can be a decimal.
Which Zod version does the output suit?
It uses only z.object, z.array, z.string, z.number, z.boolean, z.null and z.infer, which exist in Zod 3 and 4.

Features

  • Schema plus z.infer type
  • Integer detection
  • Nested objects and arrays
  • Runs in your browser

Related resources

Guides and videos from around the web—opens on YouTube or the publisher’s site.

  • TypeScript in 100 Seconds

    Fireship

    Typed JSON payloads show up constantly next to format/validate tools.

    Watch on YouTube
  • What Is A RESTful API?

    Traversy Media

    Most APIs exchange JSON—context for pretty-print and schema checks.

    Watch on YouTube
  • Base64

    MDN

    When Base64 is appropriate versus raw binary transfer.

  • Introducing JSON

    json.org

    Canonical JSON grammar—handy when a formatter rejects a trailing comma.