JSON to Zod
Infer Zod schemas from JSON.
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
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?
Does it add.optional() for missing fields?
Why is my number marked.int()?
Which Zod version does the output suit?
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 YouTubeWhat 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.