JSON to Zod

Generate Zod schemas from JSON

JSON input

Exported as a const. The inferred type is exported as Root.

Limits: 5 MiB per file or 5,242,880 characters, 256 nesting levels.

Zod schema

Every array item is inspected: differing types become z.union(...), and keys missing from some objects become .optional(). Treat the result as a starting point and tighten it with formats, enums or limits.

What JSON to Zod does

JSON to Zod turns a sample JSON payload into a Zod schema you can use for runtime validation in TypeScript. The JSON is first inferred into a library-neutral schema tree and then emitted as Zod code, so the result covers strings, numbers, booleans, null, nested objects, arrays and arrays of objects. The download is a ready-to-import .ts module with import { z } from "zod", the exported schema and an exported type built with z.infer.

How to use
  1. 1.Paste sample JSON, upload a .json file, drop a file onto the editor, or load the example.
  2. 2.Set the root schema name, for example UserSchema; the exported type becomes User.
  3. 3.Review the generated code and any notices about uncertain types.
  4. 4.Copy the code or download it as a .ts file. Clear empties the editor.
How types are inferred
  • •Every array item is inspected, not just the first one. Items of different kinds become z.union([...]).
  • •Objects inside the same array are merged: a key missing from some objects becomes .optional(), and a key that is sometimes null becomes a union with z.null().
  • •An empty array has no evidence, so its items are z.unknown() and a notice is shown.
  • •A value that is only ever null stays z.null() with a notice, because the real type cannot be known from the sample.
  • •Keys are always quoted, so names such as "user-id" or "__proto__" are handled safely.
Limits and accuracy

A sample shows what data looked like once, not the full contract. Add formats (email, url, datetime), enums, min/max or .strict() yourself where your API guarantees them. Integers beyond JavaScript's safe range are flagged because they lose precision when parsed. Input is limited to 5 MiB and 256 nesting levels, and everything runs in your browser.

CodingTool is officially live on

Launched on StartupBaseCodingTool.dev - Free, Fast & Easy Developer Tools in One Place | Product HuntCodingTool - Featured on Startup FameFazier badgeListed on Turbo0Featured on Twelve ToolsFeatured on Findly.tools