JSON to TypeScript
Paste a JSON sample and get TypeScript interfaces that describe it, with optional fields found across the items of a list. Nothing is uploaded, so real payloads are safe to use.
- Free to use
- Local processing
- Interface or type
- Optional fields detected
- Runs on your device. Files are never uploaded.
- Free and unlimited. No sign-up, no watermark.
JSON to TypeScript types in three steps
No account, no email, no waiting for an upload.
- STEP 01
Paste a JSON sample
Use a real response if you can. More items give better results.
- STEP 02
Set the names and style
Name the top type, choose interface or type, and decide whether to add export.
- STEP 03
Copy the .ts output
Nested objects get their own named types, listed from the root downward.
What JSON to TypeScript types does, and what it doesn't
We'd rather tell you up front than surprise you after the download.
What you get
- Nested types are named for youA key called address becomes an Address type. Plural list names are singularized, so users gives User.
- Optional fields from arraysWhen objects in a list do not all have the same keys, the missing ones are marked with a question mark.
- Unions where neededA field that is sometimes a string and sometimes null becomes string | null.
- Interface or type aliasChoose the declaration style that matches your codebase.
- Safe property namesKeys that are not valid identifiers, such as first-name, are quoted.
Good to know
- Types come from the sampleA field missing from every item in your sample will not appear. Use the widest example you can.
- Integers and decimals are both numberTypeScript has one number type, so no distinction is made.
- No enums or datesStrings stay as string even when they hold dates or a fixed set of values. For a contract with formats, see the JSON schema generator.
Your data never leave your device
The tool runs inside your browser instead of on our servers, so there is nothing to upload, store or delete afterwards.
Typical online tool upload
Your file travels over the internet, sits on someone else's computer for a while, and you wait for the upload and the download.
Mediaextractr no upload
The tool loads into your browser once, then works on your file locally. Nothing is sent, so nothing can leak.
When people use JSON to TypeScript types
Type an API response
Get a quick starting point for a fetch call in a TypeScript project.
Model a config file
Create types for a JSON settings file that your app reads.
Learn the shape of data
See how nested objects map to interfaces.
Speed up prototypes
Skip writing types by hand, then tighten them up.
Mediaextractr vs typical upload tools
| MediaextractrPrivate | Typical upload tools | |
|---|---|---|
| Your file is uploaded | Never | Yes |
| Sign-up needed | No | Often, after a few files |
| Daily file limit | None | Often 1–2 free files |
| Watermark | Never | Sometimes |
| Wait for upload & download | No | Yes |
| Speed on very large files | Depends on your device | Depends on their servers |
How types are inferred
Each JSON value is mapped to a TypeScript type: text to string, numbers to number, true and false to boolean, null to null, lists to arrays and objects to interfaces. For lists of objects, all items are merged, and any key absent from some of them becomes optional.
An empty list has no items to learn from, so it becomes unknown[].
Make the output production-ready
Generated types are a draft. Review them before committing:
- Rename generic names like Root to something meaningful.
- Narrow strings to unions where you know the allowed values.
- Add readonly or Date types where your code needs them.
- Check the sample first with the JSON validator.
- For runtime checks, create a schema with the JSON schema generator.
Keeping types honest
Generated types describe the sample, not the API. If a field can be missing, make sure at least one sample item lacks it, so it is marked optional. If it can also be null, include a null example. Then treat the output as a draft, and add the types to your test suite by validating real responses against a schema from the JSON schema generator.
Questions, answered
How do I generate TypeScript types from JSON?
Paste a sample, choose interface or type, and copy the result.
Can I paste a real API response without it being uploaded?
Yes. Types are inferred by code running in this tab, so sample data with real names or IDs stays on your device.
How are optional properties decided?
If a key is missing from some objects in a list, it is marked optional with a question mark.
Can I name the root type?
Yes. The name of the top type is a setting; the default is Root.
Does it handle arrays of mixed types?
Yes. They become union types such as (string | number)[].
Does it work on phones?
It does, in current mobile browsers, although editing the generated code is easier on a computer.