Paste JSON and get TypeScript interfaces or types. Nested objects and arrays become their own types.
No sign-up, no fees.
Turn JSON into TypeScript interfaces or types.
Nested objects and arrays become their own types.
Fields missing from some array items come out optional (?).
What you type is processed, but never shared with anyone.
How to generate TypeScript types from JSON
Writing types by hand for an API response is tedious, and it's easy to miss a field. Three steps:
Paste the JSON. Put an API response or config file into the JSON text box.
Adjust. Type the root type name, pick interface or type, and add export or readonly if you want.
Copy. Take the TypeScript below with Copy into your project.
What is JSON to TypeScript conversion?
TypeScript adds type checking to JavaScript. If you describe the shape of the JSON an API returns (which field is text, which is a number), your editor warns you when you use the wrong field and autocomplete starts working. This tool looks at the real values in your JSON and works out the types itself: text is string, numbers are number, true/false is boolean, and empty values are null. Nested objects are split into separate interfaces named after their keys.
What you need to know
Array merging: Objects in the same array are merged into one type. If a field is missing in some of them, it's written as optional with ?.
Mixed arrays: An array like [1, "a"] becomes (number | string)[]. An empty array has no content to learn from, so it's unknown[].
One sample only: The tool sees just the sample you paste. A field that's null here could be text in another response; to be sure of the real schema, put several samples together in an array.
Invalid names: Field names like a-b are written in quotes.
Tips
If the JSON is broken, find the problem first with the JSON formatter.
To see how two responses differ, there's the JSON diff tool.
After you have the types, you can shrink the sample with the minify option of the JSON formatter.
Frequently asked questions
Is generating TypeScript types from JSON free?
Yes, it's free and needs no sign-up.
Should I pick interface or type?
Both work for object shapes. Libraries usually prefer interface, while type is common for unions and aliases. The tool produces either.
Is my JSON sent anywhere?
What you type is processed, but never shared with anyone. The conversion runs in your browser.
Does it work with big JSON?
JSON of a few hundred KB is fine. Very large files can slow the browser down; pasting a representative part is enough.
How does it find optional fields?
It looks at the objects in an array: a field present in all of them is required, one missing from some is written as optional with ?.