Home JSON to Zod

JSON to Zod schema generator

Paste a JSON array and get the Zod schema that validates it — nesting kept, optional keys marked, and string formats recognised where Zod can check them.

Other languages:TürkçeDeutsch中文हिन्दीРусский

What the full sample tells you

Inference reads every record you paste. Include records with absent keys, nulls, mixed numbers and empty arrays so the generated types describe those cases.

  • Missing keys become optional. A key absent in any record can be omitted.
  • Null values remain nullable. A key can be both optional and nullable.
  • Integers and decimals share a number type. Target-specific output may distinguish them only when all observed values allow it.
  • String shapes are recognized where supported. Targets can preserve UUID, date, timestamp, email and URL annotations.
  • Empty arrays leave their element type unknown. Add representative elements before relying on the result.

The result describes the sample. Review it against your API contract before using it as a type or validator.

String formats become refinements

Zod can check more than "this is a string", so where every value in a field matches a recognised shape the generated schema says so:

Every value looks likeEmitted as
a UUIDz.string().uuid()
an ISO 8601 timestampz.string().datetime()
an email addressz.string().email()
an http or https URLz.string().url()
a whole numberz.number().int()

Every value, not most — one value that does not match drops the refinement, because a validator that rejects your own data is worse than one that checks less.

Declaration order is not cosmetic

Nested schemas are emitted before the schema that references them. A const used above its own declaration is a ReferenceError the moment the module is imported — not a type error, a crash — so the file is written innermost-first even though that puts the schema you came for at the bottom.

Getting the type back out

The generated file ends with an array schema for the whole payload. Add z.infer where you need the static type, so the schema stays the single source of truth rather than being kept in step with a hand-written interface:

export type User = z.infer<typeof userSchema>;
export type UserList = z.infer<typeof userListSchema>;

If you only want the static type and no runtime validation, the TypeScript generator emits interfaces directly.

Common questions

Which Zod version does the output target?

The output uses z.object, z.array, z.union, .optional(), .nullable() and the string refinements .uuid(), .datetime(), .email() and .url() — all of which are present in Zod 3 and Zod 4.

Why are nested schemas defined before the one that uses them?

Because a const referenced above its declaration throws a ReferenceError when the module is imported. Order is correctness here, not style, so the file reads innermost-first.

When does it add .email() or .uuid()?

Only when every value in that field matches the shape. One value that does not drops the refinement, because a validator that rejects your own data is worse than one that checks less.

How do I get a TypeScript type from the schema?

Add z.infer<typeof schemaName>. Keeping the schema as the source of truth is the point — a hand-written interface next to a schema is two things to keep in step.

Does the JSON get uploaded?

No. This tool processes your input in your browser without uploading it.

Last updated