Convert JSON to TypeScript in one step
Paste an API response or config file and get TypeScript interfaces that describe it, so your editor can autocomplete and type-check the data instead of treating it as any.
How to use it
- Paste a JSON sample into the Input panel, open a file, or drop it onto the page. A sample is already loaded so you can see the result.
- The TypeScript code appears instantly in the Output panel and updates as you type.
- Rename the top-level type under Settings → Root type name, and use Sort keys to order fields alphabetically.
- Copy the code or Download it as
Root.ts.
What the TypeScript generator produces
- An
export interfacefor every object shape; nested objects get their own named interface (for exampleusersbecomesUser). - Keys missing from some array items become optional with
?. - Mixed arrays become union types such as
(string | number)[]. - Keys that are not valid identifiers are quoted; identical shapes are reused instead of duplicated.
Using the generated TypeScript code
Save the interfaces to a file and use them to type parsed data:
import type { Root } from './types';
const res = await fetch('/api/data');
const data: Root = await res.json();
console.log(data.users[0].name);
More JSON tools
All tools are free and run privately in your browser.
JSON to TypeScript FAQ
Does it generate types or interfaces?
Interfaces for every object, plus a type alias when the top-level value is an array or a primitive.
How are optional properties detected?
If a key appears in some objects of an array but not in others, it is marked optional with ?. Values that are sometimes null get a | null union.
Is my data uploaded to a server?
No. The JSON to TypeScript runs entirely in your browser using JavaScript. Your data is never uploaded, logged or stored, and the tool keeps working offline after your first visit.