About the JSON to TypeScript tool
Typing API responses by hand is slow and error-prone, especially for deeply nested payloads. This JSON to TypeScript converter reads a sample response and writes the interfaces for you, so you can paste them straight into your project and get autocompletion and type checking immediately.
The generator walks the whole document and builds a named type for every nested object, naming it after its key in PascalCase. Arrays are merged rather than typed from the first item: if some objects in an array have a key that others lack, that property becomes optional with a question mark, and if a property holds different kinds of values, a union such as string | number is produced. Empty arrays become unknown[], nulls become null unions, and keys that are not valid identifiers are quoted. Identical object shapes are declared once and reused.
You can set the root type name, choose between interface declarations and type aliases, add or remove export, and treat null fields as optional. Remember that the result can only be as complete as your sample, so paste a response that includes the optional fields you care about.
How to use JSON to TypeScript
- Paste a JSON object or array into “JSON sample”, or click “Load sample”.
- Type a name in “Root type name”, for example User or ApiResponse.
- Choose “interface” or “type alias” under “Declare as” and toggle “Add export”.
- Turn on “Null fields as optional” if null means “missing” in your API.
- Copy the “TypeScript types” output or download it as a .ts file.
Features
Nested interfaces
Every nested object becomes its own named interface instead of an inline blob.
Smart array merging
All array items are combined, so missing keys become optional and mixed types become unions.
Deduplicated shapes
Identical object structures share one declaration.
Interface or type alias
Match your codebase style with interface declarations or type aliases, with or without export.
When to use it
- Type a REST API response before writing a fetch wrapper.
- Create interfaces for a JSON config file loaded in a Node.js script.
- Model webhook payloads from Stripe, GitHub or Shopify samples.
- Speed up migrating a JavaScript project to TypeScript.
Frequently asked questions
How are optional properties detected?
Within arrays of objects, a key that appears in some items but not all is marked optional. For a single object, every key present is required, because the sample cannot show what might be missing.
Should I use interface or type?
Both work for object shapes. Interfaces can be extended and merged, type aliases can express unions. Many teams simply pick one for consistency, which is why the tool lets you choose.
Why do I see unknown[]?
The array was empty in your sample, so there was nothing to infer an element type from. Add an item to the sample or edit the type manually.
Are dates converted to Date?
No. JSON has no date type, so ISO date strings are typed as string, which matches what JSON.parse returns.
Is my JSON sent anywhere?
No. The types are generated in your browser, so private API data stays on your device.