JSON to TypeScript
Paste JSON and get TypeScript interfaces with a separate type for each nested object.
Add JSON and click Generate to see the code here.
How JSON to TypeScript works
Generates TypeScript types from a JSON sample. Each JSON object becomes its own type, and nested objects are named after their key. For example, an array under "users" gives a User type.
For an array of objects, all items are merged into one type. Keys that only some items have are marked optional with ?. Change Name or Style after generating and the output updates right away.
Input to JSON to TypeScript
- Paste or type JSON into the input box, or upload a .json or .txt file. Then click Generate.
- Name sets the main type name. Default is RootObject.
- Style picks Interface (export interface) or Type alias (export type).
- Input must be valid JSON. If something is wrong, you see the line and column of the first error. Files up to 20MB, and everything runs in your browser.
Output from JSON to TypeScript
- TypeScript code with one exported type for each object shape.
- Values become string, number, boolean or arrays like string[]. Null values add | null, and mixed types become unknown.
- Keys that are not valid names, like "first-name", are kept in quotes.
- Copy it, download it as types.ts or open it in full screen.