BRev Free Tools
At BRev Digital, essentials should be a right — free, forever.
Open in workspacekeep several tools open at once
All tools
JSON to types

JSON to Zod schema

TypeScript interfaces vanish at compile time — at runtime, an API can send anything and your "typed" code will happily crash three functions later. A Zod schema is the missing half: z.object(...).parse(data) validates the payload at the boundary and throws a precise error at the exact field that is wrong.

Paste a JSON sample and the schema is built for you: nested z.object shapes, z.array, unions for mixed values — with the static type recovered via z.infer<typeof Schema>, so you keep compile-time types without writing them twice.

Optionality survives too: a field missing from some samples becomes .optional(), a field that is present but null becomes .nullable() — Zod treats them differently for good reason, and so does this generator.

Inputpaste JSON samples or a schema — multiple samples merge into one type
Loading the type generator…
Generated typesregenerates as you type
Loading the type generator…

How JSON type inference works

The generator reads your JSON and builds the strictest type that fits every value it saw: objects become interfaces, structs or classes; arrays become typed lists; a value that appears as both a number and a string becomes a union. Repeated string values (like "active" / "inactive") can be promoted to an enum, and ISO 8601 timestamps or UUIDs can map to your language's date and UUID types — both are toggles above.

Why add multiple samples?

One API response rarely shows every field — optional fields are missing, nullable fields happen to be set. Add two or three real responses with Add sample and they merge into a single type: a field present in every sample stays required, and a field that only some samples carry becomes optional. More samples always produce a more honest type.

Nullable is not optional

A field that appears as null in a sample is nullable — it is always present, but its value may be null (string | null). A field that is missing from some samples is optional — it may not exist at all (field?: string). Serializers treat the two very differently, which is why the generator keeps them distinct instead of collapsing both to "maybe".

JSON Schema in, types out

Already have a JSON Schema? Switch the input to JSON Schema and the types are derived from the schema's declared properties, required list and formats instead of being inferred from samples — or pick the JSON Schema output target to go the other way and generate a schema from samples.

Generated on your device with the quicktype engine — nothing is uploaded.

FAQ

Why Zod instead of a plain TypeScript interface?

An interface checks your code, not your data. Zod checks the data at runtime — a renamed field in an API response fails loudly at parse() instead of surfacing as undefined deep inside your app. z.infer then derives the interface from the schema, so you get both from one source.

Does my JSON leave the browser?

No — schemas are generated on your device. Nothing is uploaded.

How are optional fields detected?

By merging samples: fields present everywhere stay required, fields absent from any sample get .optional(). Null values get .nullable() instead — the two are distinct in Zod, matching how serializers behave.

Can I validate my sample right now?

This page generates the schema; run it in your project with Schema.parse(data) or the non-throwing Schema.safeParse(data) to validate live payloads.