Tool

JSON to Zod schema

Turn JSON samples into Zod 3 schemas with z.infer types locally: nested z.object dedup, optional/nullable/union mapping, copy or download.

1. JSON samples

Input stays in this tab: a local worker infers the structure, with no upload, URL fetching, storage or API calls.

Inferred from samples, not a complete API contract. Add varied real samples, review missing fields, null and empty arrays, then confirm the output with the API owner.

Limits and interpretation

A field missing from some object samples becomes optional; explicit null stays null or forms a union. Empty arrays infer unknown[] until non-empty array samples provide evidence. Mixed values form unions; repeated object shapes share a named type. First-seen field order and two-space indentation are stable. Numbers infer number, never enums or date formats.

Limits: 500,000 characters, 20,000 JSON values, 500 inferred fields and 64 nesting levels. Duplicate keys and unsafe numeric integers are rejected with source positions to avoid silently losing evidence. This tool does not generate OpenAPI documents, fetch URLs, validate live backend responses or infer future fields from a single example.

FAQ

What does the Zod output look like?

Each object shape becomes a z.object schema const; nested repeated shapes are deduplicated. The root is exported plus a matching z.infer type alias, e.g. export type ApiResponse = z.infer<typeof ApiResponse>.

How are optional and null fields mapped?

Fields missing from some samples get .optional(). A union containing only null plus one other kind collapses to .nullable(); wider unions emit z.union([...]).

Do I need zod installed?

Yes — the output starts with import { z } from "zod" and targets Zod 3-style schemas. Nothing runs in your project; copying the file is safe until you import and review it.

Can I edit inferred fields before copying?

Yes. The field table below the output lets you override any field type or flip optionality; the Zod schema regenerates in sync with the TypeScript and JSON Schema outputs.

Is my JSON uploaded?

No. Inference runs in a local worker inside this tab — no upload, no URL fetch, no storage.

Related tools

Related: local SQL formatter and whitespace compressor