JSON to TypeScript Converter
Turn a real API response into TypeScript interfaces, with nested objects extracted into their own named types.
Your data stays on your device
Input — JSON
- characters
- 0
- lines
- 0
- size
- 0 B
Output — TypeScript
- characters
- 0
- lines
- 0
- size
- 0 B
Options
About this tool
Writing types by hand from a sample response is mechanical work that gets stale the moment the API changes. Generating them from an actual payload is faster and, more importantly, describes what the endpoint really returns rather than what the documentation claims.
The generator walks the JSON recursively. Every object becomes a named type, arrays are typed by unifying their elements, and structurally identical nested objects are emitted once and reused instead of producing near-duplicate interfaces.
How to use this tool
- Paste a representative JSON response into the input panel.
- Set the root type name — this is the name your top-level interface gets.
- Choose interface, type alias or class, and set naming and optionality options.
- Press Generate, then copy the code or download it as a .ts file.
Key features
- interface, type alias or class output
- Nested objects extracted into separate named types and reused when identical
- Array element types unified, producing unions such as (string | number)[]
- Optional properties for keys that are absent in some array elements
- readonly modifiers and export keywords as options
- Reserved words and invalid identifiers quoted so the output always compiles
Example
Input — JSON
{"id":7,"owner":{"name":"Ada","email":"[email protected]"},"tags":["a"]}Output — TypeScript
export interface Owner {
name: string;
email: string;
}
export interface Root {
id: number;
owner: Owner;
tags: string[];
}Good to know
- Types are inferred from one sample. Fields that are null in the sample cannot be typed more precisely than null unless you enable nullable-widening.
- The generator cannot know that a string is a date, an enum or a branded id. Date detection is available as an option but is heuristic.
- Empty arrays yield unknown[], because there is no element to inspect.
Frequently asked questions
interface or type?
Interfaces support declaration merging and produce clearer error messages for object shapes, which is why they are the default. Type aliases are the better choice if you plan to build unions or mapped types on top of the result.
How are optional properties decided?
When the input is an array of objects, any key missing from at least one element is marked optional. With a single object every key is required, since there is no evidence otherwise.
Why did two nested objects become one type?
Because they have identical key sets and value types. Reusing the type keeps the output small and reflects that they are the same shape.
What happens to a key like "class" or "2fa_enabled"?
It is emitted as a quoted property name, which is valid TypeScript. Enabling camelCase conversion produces a legal identifier instead.
Your data stays on your device
Your data is processed locally in your browser and is not uploaded to our server. This page keeps working after you go offline, because there is nothing to send.