JSON to TypeScript Interfaces
Paste or open JSON and get TypeScript interfaces at once; nothing is uploaded.
Processed on your device. Nothing is uploadedHow to check
Paste text instead
Pasted text stays in this tab and is never sent anywhere.
Stop writing interfaces for an API response by hand. Paste the JSON you got back, or open a saved .json file, and the page writes TypeScript interfaces for it straight away: one interface per nested object, typed arrays such as Order[], and a ? on every key that some items leave out. Copy the code into your project or download it as a .ts file. The types are inferred in your browser, so a response with customer data or tokens never leaves your device.
Why use JSON to TypeScript
Private
Your JSON is read and the interfaces are written by your own browser; nothing is sent to a server.
Ready for strict mode
Optional keys get ?, null values are typed as null, and every nested object gets its own named interface.
Works offline
After you have used it once, it keeps working without an internet connection.
How it works: generate TypeScript interfaces from JSON
Paste or open a JSON sample
Paste a response into the box, drop a .json file, choose one, or try a sample.
Read the interfaces
The TypeScript code is shown at once: the top-level interface first, then one for each nested object.
Copy or download
Copy the code into your editor or download it as a .ts file. The JSON stays open in the viewer if you want to adjust the sample.
What the JSON to TypeScript generator handles
- Nested objects: each becomes its own exported interface, named after its key.
- Arrays: typed by their items, such as string[] or LineItem[]; objects in one array are merged into a single interface.
- Optional keys: a key missing from some objects in an array gets ?.
- Mixed values: a key holding a number in one item and a string in another becomes a union such as number | string.
- Keys that are not valid identifiers, such as "first-name", are written in quotes.
- Input from a .json file, a drop, the paste box or a sample, up to 10 MB.
JSON to TypeScript: what it can't do
- Types come from the one sample you give: a key or a value type that never appears in it is not known.
- TypeScript has one number type, so integers and decimals both become number.
- Very large documents may take a few seconds; files up to 10 MB.
JSON to TypeScript: questions and answers
- Is my file uploaded?
- No. The JSON is read and the interfaces are generated by your browser, on your device. Pasted text stays in this tab and is never sent anywhere.
- When does a property get a question mark?
- When it is missing from at least one object in the same array. If every item in your sample has the key, it is required, even if the real API sometimes leaves it out.
- Interfaces or type aliases?
- The page writes interfaces. They work the same as type aliases for object shapes, and you can extend them later with extends.
- What does an empty array or a null value become?
- An empty array gives no item type to learn from, and a value that is always null tells only that it can be null. Add an item or a real value to the sample, or fix those few types by hand.
- Can I paste a list of records with different keys?
- Yes. Objects in one array are merged into a single interface: keys found in every item are required, the rest get ?.
- Does it check the data at runtime?
- No. Interfaces exist only at compile time. To check real responses as they arrive, use a validation library or a JSON Schema in your code.
- How do I generate TypeScript interfaces from JSON?
- Paste a JSON sample into OpenAnyDoc's JSON to TypeScript generator and the interfaces appear at once: the top-level one first, then one for each nested object. Copy the code or download a .ts file; the JSON stays in your browser.
Why it's private: your files never leave your browser
Most online viewers upload your file to a server, so a copy of it leaves your device. OpenAnyDoc works the other way round: your browser reads the file and draws it on your screen. Nothing is uploaded, there is no account, and the file is gone from memory when you close the tab, so there is nothing for us to store, see or lose.
How we tell you about new features
Announcements are based on the release date shown to everyone, and nothing is stored on your device or sent anywhere.