JSON to TypeScript
Paste a JSON sample and get TypeScript interfaces that describe exactly what the sample contains.
TypeScript draft
No types generated yet.
Generate types first, then copy.
Why use our JSON to TypeScript Interface Generator?
One Interface per Shape
Every nested object becomes its own exported interface with a readable name, instead of an inline anonymous type you would have to pull apart by hand.
Honest Unions, No Guesses
A mixed array becomes a union of exactly the types it holds, and an empty array stays unknown[], so the draft never invents a type the sample does not show.
Parsed in Your Browser
Parsing and inference run in this page with the browser's own JSON parser. The page does not upload the sample or place it in the URL, but site scripts, analytics, and browser extensions still run in the page context.
What is a JSON to TypeScript Interface Generator?
A JSON to TypeScript interface generator reads a JSON sample and writes TypeScript interfaces that describe exactly what the sample contains. An object at the top becomes an exported interface; a root array or a single value becomes an exported type alias instead. The root type is called Root unless you rename it.
TypeScript describes the set of values a variable may hold, but a single response shows only one member of that set. The output is a draft that is accurate about the sample and silent about everything else, so check it against real API documentation, or paste a response that contains every shape you expect.
How the Draft Is Built
- Nested objects:Each nested object shape becomes its own exported interface, named by appending the property name in Pascal case (ProfileAddress, ProfileContacts) rather than an inline anonymous type, which keeps the output readable and lets you reuse a shape.
- Name clashes:Clashing names get a number suffix instead of being merged.
- Quoted keys:Keys that are not valid identifiers are quoted, with quotes and backslashes escaped so the emitted text always parses.
- Arrays of objects:Objects in an array are merged field by field, and a key missing from any of them becomes optional. Every other key is required, even if the real API sometimes omits it, and a merged result can differ from the first element you looked at.
- Empty arrays:An empty array has no element evidence, so it becomes unknown[] and the compiler forces you to narrow it. The inconvenience is deliberate: the alternative is inventing a type from nothing.
- Mixed arrays:A mixed array becomes a union of exactly the observed members in alphabetical order, such as Array<null | number | string>, so the same set always produces the same text and committed types diff quietly.
- Null:Null stays its own member, because a nullable field behaves differently at the call site and TypeScript will not warn you if the null disappears.
Common Use Cases
Typing an API Response
Paste one response from an endpoint you call and get interfaces for the parsed body to start from, instead of typing every field by hand.
Starting a Types File
Use the draft as the first version of a types module, then add the readonly modifiers, literal unions and validators your domain needs.
Webhook Payloads
Paste the sample event from a provider's documentation and get a first draft of its shape to refine against the documented fields.
How to generate a TypeScript draft
Paste a representative sample
Paste a representative JSON sample into Paste JSON, or press Load sample to try the built-in example first.
Choose a valid root type name
Use letters, digits, underscore or dollar sign, not starting with a digit and not a reserved word. Leave it empty to get Root.
Generate and inspect
Press Generate types and inspect the resulting interfaces, especially optional properties, nulls, and unknown arrays.
Compare, then export
Compare the draft with your API contract, edit any missing shapes, then copy the types or download the .ts file.
What a sample cannot tell you
Fields the Sample Lacks
If a field is absent from the sample, this tool has no evidence it exists, so the draft leaves it out.
Array Members Not Seen
If an array holds three numbers, nothing proves a fourth will not be a string. Paste a response that shows every element type you expect.
Optional Keys
Optional fields only appear when the sample shows the difference. Including several objects in an array is often the simplest way to improve the draft.
Enums
Enums are not inferred from sample values. A status value of shipping might be one of five strings, but the sample proves only one, so the generator writes string and leaves any union of literals to you.
Dates and String Formats
JSON has no date type, so dates stay string: mapping a key named createdAt to Date would break at runtime when the API returns a string. A UUID and a sentence are both string too, because guessing formats would be wrong often enough to cost more time than it saves. Numeric identifiers stay number.
Intent You Add by Hand
Readonly modifiers, branded types, index signatures, and runtime validators encode intent a value cannot express, so add them by hand. The edit is usually short, and it keeps the decision with the person who knows the domain.
Size Limits, Privacy and Export
- •Values: The page stops at 20,000 values, with its own message.
- •Nesting: JSON nested deeper than 24 levels stops with its own message naming the limit.
- •Input size: Input over 2,000,000 characters stops before parsing, again with its own message.
- •Not a verdict: These limits guard against a paste locking up the tab; they do not mean larger payloads are invalid JSON.
- •Root name first: The root type name is validated before any output is produced, because a reserved word such as interface or a name starting with a digit would emit TypeScript that cannot compile. The message states the naming rule so you can rename the root and generate again.
- •Invalid JSON: A paste that is not valid JSON is rejected with the parser's message. The JSON formatter also reports invalid JSON and pretty-prints the sample.
- •Redact first: Redact customer data, internal identifiers, and tokens before pasting a real API response anywhere, including a local tool, because the page cannot control what a browser extension does.
- •Download: Download writes a .ts file named after the root type, ready to drop into a types folder and adjust to your naming conventions.
- •Copy: Copy places the same text on the clipboard; if the browser blocks clipboard access, the output box is selected so you can copy manually.
- •Stale output: Changing the JSON or the type name after generating marks the result stale and empties both targets, so you never export text that describes a different sample from the one on screen.
Generate TypeScript Types from JSON
Paste one response, name the root type, and press Generate types to get exported interfaces you can copy into your project and refine.
No account and no install. Press Load sample first to see how nested objects, nulls and arrays come out before you paste your own data.
Example: a sample and its draft
With a root name of Profile, the sample in the first block generates the interfaces in the second.
{"name":"Ada",
"address":{"city":"Oslo"},
"contacts":[{"id":1},
{"id":2,"email":"ada@example.com"}],
"tags":[]}export interface ProfileAddress {
city: string
}
export interface ProfileContacts {
id: number
email?: string
}
export interface Profile {
name: string
address: ProfileAddress
contacts: ProfileContacts[]
tags: unknown[]
}Email is optional because only one contact has it, and tags becomes unknown[] because the array is empty.