formatjson.pro
Validate, pretty-print or minify JSON in your browser — nothing is uploaded.

JSON to Zod Schema

Paste a sample JSON object below and generate [Zod](https://zod.dev) schemas as named `export const` values. The tool infers a Zod type for every field and creates a schema for each nested object, so you get runtime validation and an inferred TypeScript type with `z.infer`.

Runs entirely in your browser — your JSON is never uploaded. Emits Zod schemas as named exports with nested schemas ordered correctly, so parse() and z.infer work immediately. No sign-up, no ads in the output.

How to generate a Zod schema from JSON

  1. Paste your JSON. Paste one representative JSON object into the box above.
  2. Generate the schema. Click Generate Zod schema. The tool infers a Zod validator for every field and emits a named schema for the root and each nested object.
  3. Validate at runtime. Copy the exports into your project and call RootSchema.parse(data) or safeParse(data); use z.infer to get the matching TypeScript type.

How the type mapping works

Each JSON value maps to a Zod validator: a whole number becomes z.number().int(), a decimal becomes z.number(), a string becomes z.string(), true/false becomes z.boolean(), and null becomes z.null(). Arrays become z.array(T) using the type of the first element.

Nested objects

Every nested object becomes its own export const NameSchema = z.object({...}), defined before the schema that references it, so the file compiles without forward-reference errors. Derive the static type with type Root = z.infer<typeof RootSchema>.

Using the result

Call RootSchema.parse(data) to validate and throw on bad input, or RootSchema.safeParse(data) for a typed success/error result — the pattern used for API responses, form input, and structured LLM output.

FAQ

Which Zod version is this for?

The output uses the standard z.object / z.string / z.number API that works in Zod 3 and later. Import z from 'zod'.

How do I get a TypeScript type from the schema?

Use z.infer: type Root = z.infer<typeof RootSchema>. The type stays in sync with the schema automatically.

How do I mark fields optional or nullable?

A single sample cannot show which keys are missing in other payloads. Add .optional() to fields that may be absent and .nullable() to fields that may be null.