What is a JSON to TypeScript generator?
A JSON to TypeScript generator writes type definitions that describe the shape of some JSON, so you get autocompletion and type checking when you use that data in code. Typing a large API response by hand is slow and easy to get wrong; generating it from a real sample takes seconds.
This generator creates one named interface or type alias per object, merges the shapes of objects in arrays, marks fields missing from some items as optional, quotes keys that aren't valid identifiers, and can make every property readonly.
How to use the JSON to TypeScript Interface Generator
1.Paste a JSON sample
A real API response works best, with arrays containing a few items.
2.Name the root type
Choose interface or type, and readonly if your code treats the data as immutable.
3.Copy into your code
Copy or download the generated .ts and adjust names to taste.
Example: a user with repos
The sample user object, with root name User:
- User
- id: number; login: string; isAdmin: boolean; tags: string[]; profile: Profile; repos: Repo[]
- Profile
- city: string; website: null
- Repo
- name: string; stars: number; archived?: boolean
archived is optional because only the second repo had it.
How the types are inferred
Each object becomes a named type, named after its key in PascalCase: a profile object becomes Profile, and items in a repos array become Repo. When an array holds several objects, their keys are merged, and a key missing from some items is marked optional with ?.
null in the sample becomes the null type, because one value can't say what else it might be; widen it to string | null by hand if needed. Keys that aren't valid identifiers, like site-url, are quoted.
Frequently asked questions
Interface or type: which should I choose?
Either works for describing JSON. Interfaces can be extended and merged; type aliases can also express unions. Many teams just pick one style.
Why is a field marked optional?
It was missing from at least one object in an array, so the generator can't assume it's always there.
Why is a field typed as null?
The sample only had null for it. Use a sample where it has a real value, or edit the type to something like string | null.
Does it validate data at runtime?
No. TypeScript types disappear when compiled. For runtime checks, use a schema library such as Zod.
Related tools
JSON Formatter & Validator
Pretty-print, minify, sort and validate JSON with line-numbered errors.
JSON ↔ CSV Converter
Convert JSON arrays to CSV and CSV back to JSON.
JSON ↔ YAML Converter
Convert JSON to YAML and YAML to JSON.
Base64 Encoder & Decoder
Base64 and Base64url for text (UTF-8) and files.
URL Encoder & Decoder
Percent-encode or decode URLs and query values, and see a URL's parts.
JWT Decoder
Decode a JSON Web Token's header and payload and check its expiry.