JSON to TypeScript
Paste JSON and get ready-to-use TypeScript interfaces. Nested objects become their own interfaces and fields that are sometimes missing are marked optional. Everything runs locally in your browser.
Generate TypeScript interfaces from JSON
Hand-writing TypeScript types for an API response is tedious and error-prone — it is easy to miss an optional field or mistype a nested shape. Paste a real sample of the JSON instead and this tool infers a complete set of interfaces for you: correct primitive types, nested objects broken out into their own named interfaces, arrays typed from their contents, and optional fields marked with ?. Drop the result into your codebase and get autocomplete and compile-time safety immediately.
How to use it
- Paste a JSON object — or, better, an array of objects — into the input box.
- Set the Root name to whatever you want the top-level interface called.
- Copy the generated interfaces on the right straight into a
.tsfile.
A worked example
Paste this:
{ "id": 10, "name": "Ada Lovelace", "active": true, "roles": ["admin"] }and you get:
interface Root {
id: number;
name: string;
active: boolean;
roles: string[];
}Paste an array of such objects and any field that is absent from some elements is automatically marked optional, which matches how real API payloads behave.
When you would reach for it
Typing a third-party API you are integrating, scaffolding models from a backend response, or converting a JSON fixture into types for a test. For runtime validation rather than compile-time types, generate a JSON Schema as well; to explore the payload first, open it in the JSON editor.
Privacy
Type inference runs entirely in your browser and works offline once loaded. Your JSON is never uploaded or stored, so it is safe to paste responses that contain tokens or customer data.
Frequently asked questions
How are optional fields decided?
When you paste an array of objects, a field that is missing (or null) in any element is marked optional with ?. For a single object, every present field is treated as required — paste a representative array if you want accurate optionality.
How are nested objects handled?
Each nested object becomes its own named interface, referenced by the parent. This keeps the output flat and reusable instead of producing one giant inline type.
What type do arrays get?
Arrays are typed from their elements: an array of numbers becomes number[], an array of objects becomes SomeInterface[]. An empty array becomes unknown[] because there is nothing to infer from.
How are mixed or null types represented?
A field that holds different types across records becomes a union (for example string | number), and a field that is sometimes null becomes ... | null.
Can I rename the root interface?
Yes — use the Root name field above. It defaults to Root; set it to something meaningful like User or ApiResponse.
Does my JSON get uploaded?
No. Interfaces are generated entirely in your browser — nothing is sent to a server.