Converters
JSON to TypeScript Converter
Paste a JSON sample and matching TypeScript types appear here, with a named type for every nested object.
Paste a JSON response and get TypeScript types for it, with a named interface for every nested object and optional fields worked out from your data.
How to use this tool
Paste a representative JSON sample, drop or Import a file, or press Sample.
Choose whether to Declare with interface or type, set the Root type name, and turn on Export or Readonly if you need them. Nested objects get their own named types, and fields missing from some array items become optional.
Check the generated types, then Copy types or Download types.ts.
How to use this tool
Paste a representative JSON sample, drop or Import a file, or press Sample.
Choose whether to Declare with interface or type, set the Root type name, and turn on Export or Readonly if you need them. Nested objects get their own named types, and fields missing from some array items become optional.
Check the generated types, then Copy types or Download types.ts.
Was this tool helpful?
Suggest an improvementHelp keep ConduitTools free
Every tool here is free, private and built by a solo developer. If this one saved you time, a small tip keeps the site running and new tools coming.
Types from real data, not guesses.
Writing types for an API response by hand is slow and error-prone. Start from a real sample and adjust from there.
- A type for every object
- Each nested object becomes its own named interface, in the order they appear, with names taken from the keys such as User or Address.
- Arrays are merged
- When an array holds several objects, they are combined into one type. A field missing from some of them becomes optional, and mixed values become a union.
- Nullable and unknown
- A null value becomes | null, and an empty array becomes unknown[] because there is nothing to learn its type from.
Frequently asked questions
Are the generated types guaranteed to be right?
They describe the sample you gave. A field that happens to be a string in your sample might sometimes be a number in production, so review the result and give it a wider sample when you can.
Interface or type?
Both describe object shapes. Interfaces can be extended and merged; type aliases are more flexible for unions. Choose whichever your codebase uses.
How are optional fields decided?
Within an array of objects, any key that is missing from at least one element is marked optional with a question mark.
What about keys that are not valid identifiers?
Keys such as content-type are written as quoted properties, which is valid TypeScript.
