Utilo

JSON to Zod Converter – Free, Online, Private

Generate a Zod schema and the inferred TypeScript type from a JSON sample, so you can validate the next payload instead of only typing it.

Input
Output

How to convert JSON to Zod

  1. Paste a representative JSON value.
  2. Copy the schema. z.infer recovers the TypeScript type.
  3. Tighten numeric strings and dates yourself. The sample cannot reveal those formats.

Schema, not just a type

A TypeScript interface disappears at runtime. A Zod schema stays and can parse. This page prints z.object schemas, an import of z from "zod", and a type alias via z.infer. Strings are z.string(), booleans z.boolean(), integers z.number().int(), other numbers z.number(). Arrays are z.array. Nested objects are their own schema constants so the file reads top to bottom. Null in the sample adds .nullable(). A key missing from some merged objects adds .optional(). Unknown is z.unknown(), used when an empty array gave the inference nothing to copy.

What validation you do not get for free

The schema accepts any string in a name field, not a min length, not an email, not a uuid. It accepts any integer for id, not a positive one. Those constraints live in product rules, not in one example. Add .email() or .min(1) after you paste. A field that looked like an ISO date remains a string. z.coerce.date() is a behavior change and is not applied silently. Unions are z.union of the variants seen in the sample. A discriminated union on a type field is not constructed; Zod can express it, but the generator would be guessing the discriminant.

Worked example

RootSchema is z.object({ id: z.number().int(), name: z.string(), active: z.boolean(), tags: z.array(z.string()) }). Root is z.infer<typeof RootSchema>. RootSchema.parse(json) throws a ZodError on the first wrong shape, which is the point of generating a schema rather than an interface. safeParse is the non-throwing form you usually want at a boundary. The page does not pin a Zod major version. The method names it emits have been stable across Zod 3.

Where it runs

Inference and printing happen in the browser. A payload copied from production is not sent to a schema service. The sibling TypeScript page emits interfaces only. Use this page when the next step is a parse at the edge of your process. Use the interface page when you already validate elsewhere and only need types for the editor.

Frequently asked questions

Which Zod version?

The output uses z.object, z.string, z.number().int(), .nullable() and .optional(), which match Zod 3.

Does parse mutate the input?

Zod's default parse returns the data and strips unknown keys. That behavior is Zod's, not something this page changes.

Can I generate z.strict?

The objects are ordinary z.object, which strips unknown keys. Add .strict() if unknown keys should fail.

Is the sample uploaded?

No. The schema text is produced locally.