Skip to content
DevTinyTools

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.

Output
0 chars
0 lines

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

  1. 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.
  2. 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.
  3. 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.
  4. 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 | string is 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” — that undefined or 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?: number means the key may be absent; it may still not be null. The generator only writes | null when 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 unknown rather 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.object calls with .optional() and .nullable() already applied, as a draft 2020-12 JSON Schema with $defs, $ref and a computed required list, 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.

Frequently asked questions

How does batch conversion work?
Select several .json files in the file picker. Each one is inferred and converted to the output you chose — TypeScript, Zod, JSON Schema or OpenAPI — with the root type named after the source file (orders.json becomes Orders). You get a per-file list with the option to save any single result, or download everything as one ZIP. Nothing is uploaded; the files are read locally like pasted text.
What does the JSON Schema output include?
A draft 2020-12 document: the root object inlined at the top level, nested objects in $defs referenced with $ref, required computed from every sampled array element, additionalProperties set to false, and integer versus number chosen the same way the Go output picks int64 versus float64. Validate it with any draft 2020-12 checker such as Ajv.
Is the OpenAPI document usable without endpoints?
Yes. OpenAPI 3.1 made paths optional, and this generator emits the parts a JSON sample can actually support: info, jsonSchemaDialect and components.schemas with every named type. Import it into Swagger UI or Postman to browse the models, or attach the components to routes you define yourself — the schema objects are standard draft 2020-12, so generators accept them unchanged.
Does it sample every array element or only the first?
Every element. The inferred shapes are merged, and a key that is missing from at least one element becomes optional rather than required. This is the difference between types that type-check against your real payload and types that only describe the first row.
What happens when the same key has different types?
You get a union, never a silent guess. A field that is 3 in one record and "3" in another becomes number | string. A null in some records joins the union as a member, and in the Zod output it becomes .nullable() instead of a three-way union where two members are enough.
Why are nested objects turned into separate interfaces?
Because inline object literals get unreadable after two levels and cannot be reused. Each nested object gets a name derived from its path — a profile object under the root type User becomes UserProfile — and the parent references it by name. The names are valid TypeScript identifiers even when the JSON keys are not.
Are dates typed as Date?
No, and that is deliberate. JSON has no date type: an ISO-8601 string is just a string, and pretending otherwise would produce code that fails at runtime. If you need Date objects, wrap the field after parsing — or use the Zod output and add z.coerce.date() where you know the format.
What about numbers that exceed 2^53?
They have already lost precision before this tool sees them. JSON.parse turns every number into an IEEE-754 double, so 12345678901234567890 arrives as 12345678901234567000 and is typed as number either way. The JSON number precision guide covers the workaround: keep identifiers as strings in the payload.
Can it read a root-level array or a bare primitive?
Yes. An array of objects names its item type after the root (Root becomes RootItem[]), and a primitive root produces a plain type alias such as export type Root = string. Arrays with an empty sample infer unknown, because there is nothing to go on.
Do keys that are not valid identifiers break the output?
No. user-name and 2fa are quoted in the TypeScript output, which is valid for object types, and the generated nested type names strip the punctuation. That keeps the file compiling instead of hand-fixing keys afterwards.
Is the JSON uploaded anywhere?
No. Parsing, inference and code generation all run in the tab. The file picker reads from disk with the FileReader API, and nothing is sent over the network — which is what makes it safe to paste a production API response.
JSON RepairFix broken JSON from an assistant or a config file: fences, comments, single quotes, trailing commas, Python literals and truncated tails — with every change reported.JSON Formatter & ValidatorPretty-print JSON with 2 or 4 space indentation, check the syntax and copy or download the result.JSON ValidatorCheck whether a JSON document is valid and see exactly where the parser stopped.JSON MinifierStrip whitespace from JSON and see how many bytes the minified output saves.JSON Diff CheckerCompare two documents and list every added, removed and changed value with its path.JSON Escape & UnescapeTurn raw text into a JSON string value, or decode backslashes and \u escapes back into readable text.JSON to CSV ConverterTurn an array of JSON objects into a CSV file you can open in a spreadsheet.JSON to Go Struct GeneratorGenerate Go structs from a JSON sample, with json tags, int64 or float64 widths, pointers for null fields and omitempty for optional keys.CSV to JSON ConverterConvert CSV to JSON with RFC 4180 parsing, delimiter detection, dotted headers unflattened into nested objects and numbers converted only when they round-trip exactly.JSON to Java POJO GeneratorGenerate Java classes from JSON: primitives for required values, boxed types for optional and nullable ones, @JsonProperty for renamed keys and nested static classes.JSON to YAML Converter (and back)Convert JSON to YAML or YAML to JSON in both directions, with multi-document support, error line numbers and YAML 1.2 typing rules.JSON to Python Class GeneratorGenerate Pydantic v2 models or dataclasses from JSON, with snake_case fields, Optional where a key is missing or null, and keyword keys renamed safely.JSON to C# Class GeneratorGenerate C# classes from JSON with nullable annotations taken from every record, initialisers that avoid CS8618 and [JsonPropertyName] for each wire key.JSON to JSON Schema GeneratorTurn a JSON sample into a draft 2020-12 schema: required keys, nullable unions and nested $defs.