JSON to TypeScript
Processed Client SideGenerate TypeScript interfaces or types from a JSON sample, with nested objects and arrays inferred.
Bookmark this tool now — skip the search next time you need it.
About JSON to TypeScript
This tool runs entirely in your browser. Whatever you paste is processed on your own device and is never uploaded, logged, or sent to any server.
Generate TypeScript interfaces or type aliases from a JSON sample, with nested objects and arrays inferred into their own named types. It goes further than mapping JavaScript types across: when an array holds objects with differing keys, fields missing from some elements are marked optional with a question mark, and fields holding more than one type become a union rather than being flattened to any. That means the generated types describe the variation actually present in your sample instead of quietly hiding it. Name the root type, choose interface or type, and paste the result into your codebase. Nested structures are hoisted into their own declarations named after the field that holds them, so what comes out is a set of types you can import individually rather than one deeply indented block.
Key features
- Generates TypeScript interfaces or type aliases from any JSON sample
- Nested objects become their own named types rather than inline structures
- Fields absent from some elements of an array are marked optional with ?
- Fields holding more than one type become a proper union instead of any
- Array element types inferred from the elements, including unions of mixed arrays
- Configurable root type name, which then drives the names given to every nested type
- Nested types hoisted into separate declarations rather than inlined, so each one can be imported and referenced on its own
- Parse errors reported with the line number, so a malformed sample is fixed in the input rather than debugged in the output
- Toggle between interface and type declarations
- Syntax-highlighted output ready to copy into your project
- Runs entirely in your browser — API payloads are never uploaded
How to use it
- Paste a representative JSON sample into the input pane.
- Set the root type name to something meaningful for your domain.
- Choose interface or type.
- Click Convert and copy the generated TypeScript.
Tips & common mistakes
- Paste the most complete and varied sample you have. Optionality is inferred from what is missing across array elements, so a single perfect record produces types where everything is required.
- A field that is null in your sample cannot be typed usefully — null alone tells the generator nothing about what it holds when populated. Fix those by hand.
- Generated types describe your sample, not your API contract. They are a fast starting point, not a guarantee, so validate real responses at runtime with Zod or a similar schema library.
- Prefer interface for object shapes you expect others to extend, and type when you need unions or intersections. The toggle here makes it a one-click decision.
- Dates arrive as strings in JSON, so they type as string. If your code parses them into Date objects, that conversion has to be reflected by hand.
- For the same job in another language, JSON to Go generates structs and JSON to C# and JSON to Java generate classes.
- An empty array in the sample carries no element type and becomes unknown[]. Include at least one populated element for every list you care about, or you will be typing that field by hand anyway.
- Array element types are named from the singular of the field, so a posts array yields a Post interface. When the field name does not singularise cleanly, that is the name worth changing before you commit the file.