JSON to TypeScript
Understand JSON to TypeScript
This generator reads a sample of JSON and writes the TypeScript interfaces that describe its shape.
How it works
It walks the sample and infers a type for every key from the value it finds: a string becomes string, a number becomes number, a nested object becomes its own named interface, and an array becomes the element type followed by []. The inference has exactly one example to work from, so the output describes that example precisely — it is a first draft you edit, not a type derived from a contract.
When to use it
- Typing a third-party API response that has no published types.
- Turning a recorded payload or a test fixture into interfaces.
- Getting a first draft of a large nested response instead of typing it out by hand.
- Seeing the real shape of a response, including fields the documentation never mentions.
Watch out for
- An optional field that happens to be absent from the sample comes out as required, and a field that is present but null tells the generator nothing about its real type. Paste a sample that includes the awkward cases, then mark the optionals yourself.
- Every number becomes number. TypeScript has no integer type, so the distinction between an ID and a price is lost — and an ID beyond 2^53 already lost precision when the JSON was parsed, before the generator ever saw it.
- A field whose type varies between responses — sometimes a string, sometimes null, sometimes an object — is typed from whichever version you pasted. The generated interface compiles and is then wrong at runtime.
Not the right tool for: Replacing a schema. If the API publishes an OpenAPI or JSON Schema document, generate types from that — it describes every response rather than one of them.
Frequently Asked Questions
How do I convert JSON to a TypeScript interface?
Paste a representative JSON response and name the root interface. Types appear as you type: nested objects become their own named interfaces, arrays are typed by their elements, and the result is ready to paste into a .ts file or download.
How are optional properties detected?
From an array of objects, any key that is absent from at least one item is marked optional with a question mark. That is why pasting several representative records produces better types than pasting a single one — the generator can only see what the sample shows it.
What happens to null values?
A null is typed as null rather than guessed at, so a key seen as both a number and null becomes number | null. Turn on "Nulls become optional" if your API uses null to mean absent, and the key becomes optional instead.
How to Use JSON to TypeScript
- Paste or type your input in the input area above.
- The tool processes your input automatically or click Run.
- Copy or download the result using the action buttons.
- Use Ctrl+Enter to run quickly from the keyboard.