JSON to TypeScript Converter
Generate TypeScript interfaces or type aliases from sample JSON. Merges array shapes, marks optional fields, builds unions — instant and private.
About the JSON to TypeScript Converter
Paste a sample JSON payload and this tool generates matching TypeScript interfaces (or type aliases) instantly. It infers each field's type — string, number, boolean, null, nested objects and arrays — and names generated types after their keys, so an API response becomes ready-to-use, fully typed models in one click.
It handles the messy shapes real APIs return. When a JSON array contains objects with slightly different keys, the converter merges them into a single interface and marks the sometimes-missing properties as optional. Fields that hold more than one type become proper unions (string | number), and deeply nested structures are split into separate, reusable named interfaces.
Choose between the interface and type styles, set the root name to match your domain, then copy the result or download it as a .ts file. Everything runs in your browser, so private payloads never leave your machine.
How to Use the JSON to TypeScript Converter
- 1Paste a representative JSON sample into the input box.
- 2Set the root type name and choose interface or type alias output.
- 3Click Generate TypeScript.
- 4Copy the definitions or download them as a .ts file.
Frequently Asked Questions
How are optional properties decided?
When the JSON root is an array of objects, the tool takes the union of all keys seen across the items. Any key that is absent from at least one object is marked optional with a ? — exactly how you'd model an API that omits null fields.
What happens with mixed-type fields?
If the same field holds different types across samples (for example a number in one object and a string in another), the generated type becomes a union like string | number, so your code is forced to handle both cases safely.
Should I use interface or type?
Both work for object shapes. Interfaces are conventional for public data models and support declaration merging; type aliases are handy when you also need unions or intersections. The converter offers both — pick whichever matches your codebase's style.
Does it validate the JSON first?
Yes. If the input isn't valid JSON, the tool reports the exact line and column of the parse error instead of generating garbage. Fix the reported spot and run it again.
Is my JSON sent to a server?
No. Type generation runs entirely in your browser, so you can safely paste real production payloads containing sensitive field names or values.