JSON to TypeScript: Interfaces, Types and Zod
Paste a JSON sample and get TypeScript interfaces, type aliases or a Zod schema as you type. Arrays of objects merge into one type, and repeated strings become enums. Nothing is uploaded.
Rate this toolTypes Studio
interface · type · Zod schema from any JSON
Your JSON
Comments, trailing commas and single quotes are fine. .
Output
TypeScript output
Paste JSON on the left. The types appear here as you type.
- Output styles
- 3Output styles
- Max enum values
- 12Max enum values
- Download
- .tsDownload
- Bytes uploaded
- 0Bytes uploaded
Do more with your types
Tools that pick up where this one leaves off.
Types from JSON in three steps
From an API response to code you can paste. No sign-up and no upload.
- STEP 01
Paste a sample
Paste a real JSON response, or drop or upload a .json file.
Comments allowed - STEP 02
Pick the output
interface, type alias or Zod schema, with your own root type name.
Updates as you type - STEP 03
Copy or download
Copy the code, or save it as a .ts file named after the root type.
Ready to paste
How to use this JSON to TypeScript converter
Input is read with JSON5, so comments, trailing commas, single quotes and unquoted keys are all fine.
- 1
Use a real sample
Paste an actual response, not a hand-written one. The more items an array has, the better the merge.
- 2
Name the root
Set the root type name, such as User or OrderResponse. Nested types are named after their keys.
- 3
Choose the style
interface for plain object shapes, type for aliases, or Zod to check data at runtime too.
- 4
Review, then paste
Check optional fields and unions against the API docs, then copy or download the file.
Habits for accurate generated types
A generator only sees your sample. These habits make the sample tell the truth.
Include varied items
Put several items in each array. Keys missing from some items become optional.
- Two or more items
- One with missing fields
- One with nulls
Show repeated values
A string set becomes a union only when a value repeats and there are 2 to 12 of them.
- "active" twice or more
- Turn off for free text
- Check against the docs
Rename after
Nested types are named from keys, like Address or RolesItem. Rename them to match your codebase.
- Root name in the studio
- Others in your editor
- Duplicates get a number
Validate at the edge
Types vanish when TypeScript compiles. Zod checks real data when it arrives.
- Zod for API input
- parse() throws
- safeParse() returns
How each JSON value becomes a type
The rules the generator applies, so you know what to check.
Objects merge
Every object in an array merges into one type with the union of all keys.
- Missing keys become key?
- Field types are unioned
- Named KeyItem
Literal unions
Repeated strings with 2 to 12 distinct values become "a" | "b".
- Needs a repeat
- Over 12 stays string
- Can be turned off
Unions for mixed values
A field that is a number in one item and a string in another becomes string | number.
- Arrays: (string | number)[]
- null joins the union
- Empty arrays: unknown[]
Safe property names
Keys that are not valid identifiers, like first-name, are written in quotes.
- "first-name": string
- Valid keys stay bare
- Order kept from JSON
Who generates types from JSON
Anyone who calls an API from TypeScript writes these types sooner or later.
Frontend developers
Fetch calls return untyped JSON. A generated interface turns it into autocomplete and checks.
Backend developers
Third-party webhooks and APIs send JSON you don't control.
Mobile developers
App screens read the same API payloads as the web, and need the same types.
QA and testers
Typed fixtures catch a test that drifts from the real response shape.
JSON values and their TypeScript types
What the generator writes for each kind of value, and what it cannot know.
Value to type
How each JSON value is typed.
- "Asha": string
- 42, 3.5: number
- true: boolean
- null: null
- []: unknown[]
- { ... }: its own interface
Structure
How nesting turns into named types.
- Each nested object gets its own type
- Array elements are named KeyItem
- Repeated names get a number
- A non-object root becomes a type alias
Can't be known
Things a sample doesn't show. Add them by hand.
- Dates (they stay string)
- Fields never seen in the sample
- Value ranges and formats
- Which nulls are really optional
Keeping generated types up to date
APIs change. These habits stop your types from drifting.
- 1
Keep the sample
Save the JSON you generated from next to the types, so the next update starts from the same place.
- 2
Regenerate on change
When the API adds a field, paste a new sample and compare the output with your file.
- 3
Validate at runtime
A Zod schema throws on parse() when real data stops matching, instead of failing quietly later.
- 4
Prefer official types
If the API ships an OpenAPI spec or an SDK with types, use those. Generated types are the fallback.
Generated types vs hand-written vs from a spec
Three ways to type an API response. Pick by what the API gives you.
| Feature | This generator | Hand-written | From an OpenAPI spec |
|---|---|---|---|
| Needs | ✓ One JSON sample | Time and the docs | A published spec |
| Speed | ✓ Seconds | ✗ Slow for big payloads | ✓ Seconds, once set up |
| Optional fields | Only if the sample shows them | ✓ From the docs | ✓ From the spec |
| Runtime check | ✓ Zod output | Write it yourself | Extra tooling |
| Stays in sync | ✗ Regenerate by hand | ✗ By hand | ✓ Rerun the build |
| Data leaves your device | ✓ Never | ✓ Never | ✓ Never |
JSON won't parse? Find the error with the JSON formatter first.
Pro tips for generated types
Small habits that make the output ready to commit.
Merge several responses
Wrap two or three responses in one array to see which fields are really optional.
Enums need repeats
One "admin" and one "editor" stay string. Add a second "editor" to get a union.
null is not optional
A null value types as null, not key?. Decide which your code should expect.
All optional for patches
Turn on All fields optional for PATCH bodies and partial updates.
Zod needs the package
The Zod output imports from "zod". Install it in your project before you paste.
Comments are fine
Paste JSON with comments or trailing commas. JSON5 reads it, and Format cleans it up.
One file per root
The download is named after the root type, like User.ts or User.schema.ts for Zod.
Private payloads
Responses with tokens or customer data are parsed in this tab and never uploaded.
TypeScript types are removed when your code compiles, so a response that doesn't match still gets through. If the data comes from outside your code, generate a Zod schema and parse it where it arrives.
interface or type? Which to generate
For plain object shapes they are almost the same. The TypeScript Handbook explains the one real difference.
interface
Can be re-opened: two interfaces with the same name merge. The Handbook suggests using interface until you need a feature of type.
Best for API response shapes
type
Can't be re-opened once created, but can name unions and other types an interface can't, like string | number.
Best when you will combine types
Who uses this JSON to TypeScript converter
Six everyday jobs that start with an untyped JSON payload.
Typing a fetch call
Turn the response of a new endpoint into an interface in seconds.
Handling webhooks
Generate a Zod schema to check webhook bodies before you use them.
Migrating JavaScript
Replace any with real types while moving a codebase to TypeScript.
Typing fixtures
Type test data so tests fail when the real shape changes.
Reading config
Type a JSON config file so a typo in a key is caught at build time.
Learning TypeScript
See how objects, arrays and unions map to types.
Have CSV instead? Convert it with CSV to JSON first.
Frequently asked questions
Quick answers about inference, Zod and privacy.
Does it handle nested objects?
Can I use 'type' instead of 'interface'?
Does it handle optional fields?
Is this free?
What people say
Reviews from people who used this tool.
Loading reviews…
More free JSON and data tools
Free, with no sign-up, just like this one.
- Free toolCSV to JSON ConverterConvert between CSV and JSON in your browser - auto delimiter detection, type inference, and a typed preview table.Try it now
- Free toolData Converter - JSON / XML / CSV / YAMLConvert between JSON, XML, CSV, and YAML in any direction - RFC-4180 CSV, browser-only, no signup.Try it now
- Free toolJSON FormatterBeautify, minify, sort, validate, and auto-repair JSON - with text + tree views, JSONPath copy, and stats.Try it now
- Free toolBase64 Encoder / DecoderEncode text to Base64 or decode Base64 strings instantly in your browserTry it now
- Free toolJWT DecoderDecode and inspect JSON Web Tokens - view header, payload, expiry, and claims instantlyTry it now
- Free toolFavicon GeneratorTurn any image into the full favicon set - six standard sizes plus the HTML meta tags ready to paste, generated locally in your browser.Try it now