JSON to TypeScript Converter
This tool generates TypeScript types from a sample of JSON. It writes an interface for each object and marks keys that are missing from some list items as optional.
- Free, no sign-up
- Nothing is sent to a server
- Worldwide
How to use JSON to TypeScript Converter online
- Paste a JSON sample. Type or paste the text.
- Name the type. Set the main type name and style.
- Set options. Export, readonly and optional null.
- Copy the types. Copy or save the result.
Why use this free JSON to TypeScript Converter
- Interfaces for nested objects
- Optional keys from lists
- Interface or type alias
- Export and readonly options
- Names made safe
- Share by link
Types from a sample
Writing types by hand for a large API response is slow. Paste a sample response, and the tool writes an interface for the main object and for each nested object. Numbers, strings and booleans get their TypeScript names, null stays null and a list becomes the element type followed by [].
Lists of objects
When a list holds several objects, the tool merges them into one interface. A key that appears in every item is required, and a key that is missing from some is marked optional with a question mark. Lists of mixed values become a union type, such as (number | string)[]. An empty list becomes unknown[], because nothing shows its type.
A worked example
The sample has an id, a name, a list of tags, an address object and a list of orders where one order has no total. The tool writes 3 types:\ninterface Root { id: number; name: string; tags: string[]; address: Address; orders: Order[]; }
interface Order { id: number; total?: number; }
interface Address { city: string; zip: null; }\nThe total is optional because only one order has it, and zip is typed null because the sample holds null.
Options
Name the main type, choose interface or type alias, add export, mark properties readonly, and make properties that can be null optional too. Keys that are not valid names, such as my-key, are written in quotes. Nested types are named from their key in PascalCase, with a number added if the name is already taken.
Check the result
The types are guessed from a single sample, so a field that was always a number in your sample may sometimes be a string in real data. Treat the output as a good starting point and check it. Add more sample items to cover more cases, and use the JSON validator first if the text will not convert.
Using the tool
Change the text or any option of the JSON to TypeScript Converter and the answer moves straight away. Undo and redo step back through your earlier text.
JSON to TypeScript Converter: frequently asked questions
How are optional keys decided?
What is generated for null?
Can I get type aliases instead of interfaces?
What about an empty list?
Is the output exact?
Is the text I paste into the JSON to TypeScript Converter uploaded?
Can I save what the JSON to TypeScript Converter gives me?
Related searches for JSON to TypeScript Converter
- JSON to TypeScript Converter online
- free JSON to TypeScript Converter
- JSON to TypeScript Converter online free
- JSON to TypeScript Converter for mobile
- JSON to TypeScript Converter without sign up
- convert json to typescript converter
- json to typescript converter converter
- JSON to TypeScript Converter – Text & Writing Tools
JSON to TypeScript Converter is a free online tool on MAITBOX, in the Text & Writing Tools group. It runs in your browser, so what you type is not sent to a server. It works on Android and iPhone, and on Windows, Mac and Linux, with no download and no account.