JSON to TypeScript
Generate TypeScript interfaces from a JSON sample instantly in your browser, including automatic nested object splitting and optional fields for mismatched array items. Quickly scaffold types for an API response, GraphQL payload, or webhook body with no upload required.
Usage examples
Quickly scaffolding a type for an API response
Paste in a sample JSON response from your server and get a TypeScript interface draft you can drop straight into your project.
Automatically splitting nested objects into their own interfaces
When your JSON contains another object, it gets its own named interface based on the field name, keeping things tidy.
Marking fields optional when array items differ
When objects in an array don't all share the same fields, they're merged into a single interface with '?' marking fields that aren't present everywhere.
Prototyping types for a GraphQL or webhook payload
Paste a sample payload like '{"event": "order.created", "data": {"id": "ord_1", "total": 42.5}}' to quickly get typed interfaces for a webhook handler, without writing them by hand.
Checking how null values are typed
Include a field like '{"middleName": null}' in your sample to see how the tool represents nullable fields in the generated interface.
Quick reference
JSON values → TypeScript types
| JSON | TypeScript |
|---|---|
| "hello" | type Root = string; |
| 42 | type Root = number; |
| 3.14 | type Root = number; |
| true | type Root = boolean; |
| null | type Root = null; |
| [] | type Root = unknown[]; |
| [1, 2, 3] | type Root = number[]; |
| ["a", "b"] | type Root = string[]; |
| [1, "a", true] | type Root = (number | string | boolean)[]; |
| [1, null] | type Root = (number | null)[]; |
| [[1, 2], [3]] | type Root = number[][]; |
| {} | interface Root { } |
JSON objects → TypeScript interfaces
| JSON | TypeScript |
|---|---|
| {"id": 1, "name": "Ada"} | interface Root { id: number; name: string; } |
| {"deletedAt": null} | interface Root { deletedAt: null; } |
| {"tags": ["a", "b"]} | interface Root { tags: string[]; } |
| {"user": {"id": 1}} | interface User { id: number; } interface Root { user: User; } |
| {"items": [{"id": 1}, {"id": 2, "note": "x"}]} | interface Item { id: number; note?: string; } interface Root { items: Item[]; } |
| {"categories": [{"name": "x"}]} | interface Category { name: string; } interface Root { categories: Category[]; } |
| {"first-name": "Ada"} | interface Root { "first-name": string; } |
| {"a": {"x": 1}, "b": {"x": 2}} | interface A { x: number; } interface Root { a: A; b: A; } |
Frequently asked questions
Is my JSON sent to a server?
No. All conversion happens entirely in your browser, and what you enter is never sent to a server.
Can I use the generated code as-is?
It's inferred from a single JSON example, so it may not capture every variation your real data can take. Treat the generated interface as a starting point and adjust it as needed.
Does it recognize date strings as a Date type?
No. JSON has no dedicated date type, so every string is treated as string. If you want it treated as a date, adjust the generated code by hand.
What happens if the same shape of object appears multiple times?
Objects with an identical structure reuse a single interface instead of generating duplicates.
How are empty arrays typed?
Since an empty array gives no clue about its element type, it's typed as 'unknown[]'. Add at least one sample element to the array if you want a more specific element type.
What TypeScript type does a null value get?
A field whose sample value is null is typed as 'null'. If you know the field can hold other types too, such as a string or being absent, you'll need to widen the generated type by hand, for example to 'string | null'.
Does field order in my JSON affect the generated interface?
No. Fields are listed in the generated interface in the same order they appear in your input, but reordering them in the source JSON has no effect on the generated types themselves.