JSON to TypeScript, Zod & Schema Generator
Paste a JSON response and get TypeScript interfaces that match it. Every array element is sampled, so properties that only some records carry come out optional instead of breaking the build. Pro adds Zod and JSON Schema output.
Runs entirely in your browser — your JSON is never uploaded.
Free generation covers up to 1,000,000 characters per document — what Pro adds. The JSON you paste never leaves the tab; inference runs in your browser.
A worked example
Every array element is sampled, not just the first record.
Input
[{"id":1,"name":"Ada"},{"id":2,"email":"ada@example.com"}]Output
export interface RootObject {
id: number;
name?: string;
email?: string;
}A key that appears in only some records becomes optional. A generated type reflects the sample, not a contract you never supplied.
How to generate TypeScript from JSON
- Paste the JSON, or open a .json file A single object and an array of objects both work. For an API response, paste the real payload rather than a hand-written sample — the types are only as accurate as the data you give them.
- Name the root type Root is the default. Rename it to ApiResponse, User or Invoice before you copy; nested types are named from it, so a profile object under User becomes UserProfile rather than a generic RootProfile.
- Choose interfaces, Zod or JSON Schema Interfaces are erased at compile time and cost nothing at runtime. The Zod schema is a runtime validator; the JSON Schema and OpenAPI 3.1 documents are language-neutral — Ajv, a CI gate, Swagger UI or Postman can all consume them.
- Press Generate, then copy or download The output panel counts the types and lines it produced. Download writes a .ts file named after the root type, ready to drop into your project.
What the inference actually decides
A JSON sample is not a schema. Two people can look at the same payload and disagree about which fields are guaranteed, so the generator follows four rules and applies them consistently:
- Missing keys become optional. With
[{"a":1,"b":2},{"a":3}], the result is{ a: number; b?: number }. Marking b as required would compile and then crash on the second record. - Disagreeing kinds become a union.
number | stringis honest; picking one is a guess that fails silently at runtime. - null joins the union. A field that is sometimes null becomes
string | null, because null carries meaning — “no value yet” — thatundefinedor an empty string does not. - Nesting is structural. Objects inside objects and objects inside arrays are compared independently, so optionality is decided at the level where the data actually varies.
One consequence is worth stating plainly: if your sample happens to contain a field in every record, it comes out required even if the API omits it occasionally. A generator can only describe the data it was shown. Paste a larger sample, or mark the field optional by hand, when you know the schema is looser than the sample. The full guide walks through what merging samples changes and where inference stops.
Interfaces or Zod: which one do you need
Both describe the same shape, and they answer different questions.
- TypeScript interfaces describe what your own code may pass around. They are checked at compile time and disappear from the bundle, so the cost is zero. They cannot validate a fetch response, because at runtime there is no such thing as an interface.
- Zod schemas are real values.
schema.parse(json)returns typed data on success and throws a structured error naming the exact path on failure. Use them at the boundaries — an API response, a config file, a webhook body — where the input is not under your control.
The usual setup is both: infer the TypeScript types from the schema with z.infer, so the validator and the types can never drift apart. That is exactly what the Zod output does — it emits the schema and the inferred alias together.
Where generated types stop being enough
- Union members are not exhaustive. A status field that is only ever
"active"in your sample is typed as string, not as the literal union. Narrow it by hand once you know the allowed values. - Optional is not the same as nullable.
b?: numbermeans the key may be absent; it may still not be null. The generator only writes| nullwhen it saw a null. - Deeply nested payloads get long names. Four levels down you get a declaration called
RootOrdersItemCustomerAddress. Rename the root type to something short before generating; the child names shrink with it. - Depth is capped. Past 32 levels the generator emits
unknownrather than a thousand-brace type. A payload that deep usually needs a schema written by hand anyway.
DevTinyTools Pro
Generating TypeScript interfaces is free and stays free. Pro is for the workflows that outgrow a single paste:
- Batch conversion — select several .json files at once, convert every one to the chosen output, and download the whole set as a single ZIP. Files that fail to parse are listed with the reason instead of blocking the rest.
- Zod, JSON Schema and OpenAPI output — the same inference, emitted as
z.objectcalls with.optional()and.nullable()already applied, as a draft 2020-12 JSON Schema with$defs,$refand a computedrequiredlist, or as an OpenAPI 3.1 document Swagger UI and Postman import directly. - Up to 10,000,000 characters per document — for the multi-megabyte API dumps that a browser tab can hold but a free session will not.
- Lifetime licence — one payment, no subscription, and the tool keeps working after the next round of updates.
Pro is $29 one-time — a lifetime licence, sold through Lemon Squeezy as merchant of record, so VAT and sales tax are handled for you. Pro is a licence key — there is still no account. Buy DevTinyTools Pro, then activate it below and the Zod output unlocks in this browser.