How do I convert JSON or JSON Schema to Zod?
Paste JSON data (the tool infers types) or a JSON Schema (precise conversion with $ref, allOf/oneOf/anyOf, format constraints, and defaults). The output is a production-ready Zod schema with .optional(), .strict(), coerce, and .describe() options. Download as .ts or copy. Everything runs in your browser.
{"name":"Alice","age":28,"email":"a@b.com"}const schema = z.object({
name: z.string(),
age: z.number(),
email: z.string().email(),
});JSON to Zod Converter
Convert JSON or JSON Schema to Zod validation schemas. Supports $ref, allOf/oneOf/anyOf, enum, format constraints, and nested objects.
About JSON to Zod Converter
- Two input modes — paste raw JSON data to infer schemas, or paste a JSON Schema for precise conversion with
$ref,allOf/oneOf/anyOf, and constraints. - JSON Schema support — converts
required,enum,const,format(email, uri, uuid, date-time, ipv4, ipv6),pattern,minimum/maximum,minLength/maxLength,default, and$defs/definitions. - Smart inference — detects emails, URLs, UUIDs, and ISO dates in raw JSON values and adds appropriate Zod refinements.
- Required vs optional — JSON Schema
requiredarrays map to required fields; all others get.optional(). - TypeScript type — generates
z.infer<typeof schema>so you get TypeScript types for free. - Everything runs in your browser — no data is sent over the network.
Tips & Best Practices
Add .transform() for runtime data coercion
Generated Zod schemas validate shape, but API data often needs transformation — date strings to Date objects, string numbers to actual numbers, empty strings to null. Chain .transform() after .parse() to clean data in the same step as validation.
z.infer<typeof schema> doesn't capture .transform() output types
z.infer gives you the input type. If your schema uses .transform(), you need z.output<typeof schema> for the transformed type. Using z.infer with transforms means your TypeScript types won't match the actual runtime values.
Validate API responses at the boundary
Parse every external API response through a Zod schema: const data = UserSchema.parse(await res.json()). This catches type mismatches immediately at the boundary rather than letting bad data propagate through your app and cause cryptic errors downstream.
Use .strict() to reject unexpected fields
By default, Zod strips unknown keys. If an attacker sends extra fields (isAdmin: true, role: 'superuser'), they're silently removed. But if you spread the parsed object into a database query, those fields might sneak through. Use .strict() to throw on unexpected fields instead of silently dropping them.
Frequently Asked Questions
How do I convert JSON to a Zod validation schema?
What is the difference between converting JSON data vs JSON Schema to Zod?
How does the converter handle nullable and optional fields?
Related Convert Tools
Case Converter
Convert text between camelCase, snake_case, kebab-case, and more
Number Base Converter
Convert numbers between binary, octal, decimal, and hex
CSV ↔ JSON Converter
Convert between CSV and JSON formats with custom delimiters
URL Encoder & Decoder
Encode and decode URLs with encodeURIComponent and encodeURI