About this tool
When you connect to an API in TypeScript, you need types for its responses. Instead of typing them by hand, paste a sample response here and instantly get interfaces or type aliases – with separate types for nested objects and array items.
Arrays of objects are merged: fields that appear in only some items become optional, different value types become unions such as string | null. Everything runs locally in your browser; your data never leaves your device. To validate and format the JSON, use the JSON Formatter & Validator; for YAML, CSV or XML, the YAML ↔ JSON ↔ CSV Converter.
How it works
- Paste a JSON sample, e.g. an API response.
- Set the name of the root type and choose interface or type.
- Enable export and readonly if needed.
- Copy the generated types into your project and refine them if necessary.
Frequently asked questions
How are arrays handled?
All items of an array are analysed together. Objects get one shared type named after the field (users becomes User). Mixed arrays become unions such as (string | number)[], empty arrays become unknown[].
When does a field become optional?
When it is missing from at least one object of the same array. A field with the value null is present and gets null as a possible type instead.
interface or type – which one should I use?
For object shapes both are almost equivalent. Interfaces can be extended and merged, type aliases are more flexible with unions. Many projects pick one with a lint rule.
How accurate are the generated types?
They reflect exactly your sample. If a field does not appear in it or a value happens to always be the same, the generator cannot know – so use complete samples and review the result. Dates appear as string because JSON has no date type.