JSON to TypeScript

One input per line. Output is numbered to match the input order.
Pinned tools are listed in your favourites on the home page.Copies a link to this tool that carries your current input, so it opens ready to run.Gives you an iframe snippet for putting this tool on your own site.

Types are inferred from one sample, so they describe that sample exactly: a key absent from some array items becomes optional, mixed arrays become element unions, and a null stays null rather than being guessed at. Output is deterministic — the same JSON always produces the same file.

Ctrl+Enter Run  · Ctrl+Shift+C Copy  · Esc Clear

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

  1. Paste or type your input in the input area above.
  2. The tool processes your input automatically or click Run.
  3. Copy or download the result using the action buttons.
  4. Use Ctrl+Enter to run quickly from the keyboard.