JSON to TypeScript: Generate Interfaces and Types Online
Paste JSON and get TypeScript interfaces or types, with nested objects, optional fields and arrays handled. Runs in your browser.
Paste a JSON response and the tool writes TypeScript interfaces for it. Nested objects get their own interface, arrays are merged so a field missing from some items becomes optional, and mixed values become unions.
What it does
- Writes an interface (or type alias) for every nested object, named after its key.
- Merges all items of an array, so a field that is missing from some items becomes optional (?).
- Shows mixed values as unions, such as (number | string)[], and null as a type.
- Quotes keys that are not valid names, like "first-name".
- Open a .json file or paste text. Nothing is uploaded.
Example
Before
{"id":1,"orders":[{"total":5},{"total":9,"note":null}]}After
export interface Order {
total: number;
note?: null;
}
export interface Root {
id: number;
orders: Order[];
}Frequently asked questions
- Does it check the types of my real data?
- It only looks at the sample you give it. If your API can return a field as a string sometimes and a number other times, include both in the sample so the union is created.
- Why is a field optional?
- It was missing from at least one item in an array. Fields that are present in every item stay required.
- What happens to empty arrays?
- An empty array has no items to learn from, so it becomes unknown[]. Put one real item in the sample to get a better type.
- Is my JSON sent anywhere?
- No. The conversion runs in your browser.
More tools
Code formatters
CSS beautifier CSS minifier HTML beautifier HTML minifier JavaScript beautifier JavaScript minifier JSON formatter YAML formatter XML formatter SQL formatter Markdown preview
Converters
Base64 encoder and decoder URL encoder and decoder Unix timestamp converter CSV to JSON JSON to CSV HTML entity encoder and decoder Number base converter Time zone converter XML to JSON HTML to Markdown Date difference calculator
Text tools
Regex tester Remove duplicate lines Lorem ipsum generator Word counter Case converter Text diff checker
Color and images
Color converter Contrast checker Image to Base64 Image resizer
Network
Subnet calculator Download time calculator Common ports list CIDR to IP range IPv6 address expander and compressor MAC address formatter curl command builder
Server and files
Cron expression explainer chmod calculator HTTP status codes
Encoding and security
Password generator UUID generator Hash generator JWT decoder QR code generator Password strength checker Wi-Fi QR code generator