Generate TypeScript Interfaces from JSON
Paste a JSON sample and get ready-to-use interfaces or types. Nested objects, arrays, and optional fields are inferred for you.
Use this tool in your browser without installing software.
About this tool
The first step with an API response is usually writing its type. This tool does that: it reads each value and infers the type from the data — string, number, boolean, nested object, and array. When members of an array have different shapes, they are merged into one interface and a key that is missing from some members is marked optional. Every nested object gets its own declaration, and two identical shapes share one type so the output stays short. You choose the root name, interface or type, export, and readonly. A field that is only null in the sample becomes any, because its real type is unknown. Everything runs in your browser; your JSON is never sent anywhere.
How to use it
- 1
Paste the JSON sample, or use the sample button.
- 2
Set the root name and output style; export and readonly sit in the same row.
- 3
Review the generated code and copy it.
If the file will not open
- Every field came out as string.
The values were quoted in the JSON. Write numbers and true/false without quotes so the right type is detected.
- The type names do not match my keys.
Each type is named after its key with the first letter capitalised. To choose a name, change the root name or rename the interface after generating.
- My JSON is rejected even though it looks fine.
JSON has no comments and no trailing commas, and every key must be in double quotes. The line and column of the error appear above the output.
- Where do I put the generated code?
In a .ts file next to your code, or a .d.ts file for shared types. For an API response, use it where you receive the response.
Frequently asked questions
How are field types decided?
From the values in the sample. A string becomes string, a number becomes number, true or false becomes boolean, and objects and arrays become nested types. If a field happens to be a string in the sample but is a number in reality, change it after generating.
Why do some fields have a question mark?
Because that key was missing from some members of an array. The ? means it may be absent; remove it if the field is always there.
Why did a field become any?
Its value was null in the sample, and null does not reveal the real type. any accepts anything; replace it with the type you know.
What type does an empty array get?
any[], because there is no element to infer from. Replace any with the real element type.
Is my JSON stored or sent anywhere?
No. The conversion happens in your browser and no request carries the data. Closing the page clears it.