JSON to TypeScript Converter
Convert JSON to TypeScript interfaces or type aliases as you type: array items merge into one type, missing keys become optional and nothing is uploaded.
Types that fit every item
All the objects in an array merge into one interface. Keys that some objects lack become optional, values that differ become unions such as string | number, and objects with the same shape share one declaration.
Written in your style
Choose interface or type, named or inline nested types, T[] or Array<T>, readonly and export, and how null values, missing keys and unknown values are written. The page remembers your choices.
Nothing leaves your browser
Parsing and type inference run on this page, so API responses and config files are never uploaded. Files up to 5 MiB are read locally, and a syntax error shows its line and column.
How to convert JSON to TypeScript
- 1
Paste JSON into the box, open a .json file or drop one onto the page. The example shows what the result looks like.
- 2
Set the root type name and choose interface or type, named or inline nested types, and how null values and missing keys are written.
- 3
Read the declarations and the notes below them, which point out keys that were always null, renamed types and integers too large for JavaScript.
- 4
Copy the TypeScript, or download it as types.ts, and add it to your project.
What people use this tool for
- Type an API response before writing the code that uses it.
- Create interfaces for a JSON config file, test fixture or mock data.
- Find which keys in a large export are optional or change type between records.
- Turn a sample webhook or event payload into types to share with your team.
Frequently Asked Questions
How does the converter work out TypeScript types from JSON?
It reads every value, not just the first one. Strings, numbers and booleans become string, number and boolean, and each nested object becomes its own interface named after its key. Arrays become T[], an empty array becomes unknown[] and an empty object becomes Record<string, unknown>. A top-level array is written as export type Root = RootItem[], and a top-level string or number as a type alias.
What happens when the objects in an array have different keys or types?
They merge into one interface. A key that some objects lack becomes optional, such as tags?: string[], and a key whose values differ becomes a union, such as id: string | number. Arrays of mixed values become unions too, for example (string | number)[]. Objects found at the same place in different items, such as every user's address, merge the same way.
Should I generate a TypeScript interface or a type?
For JSON data both describe the same shapes, so it is mostly a matter of style. Interfaces can be extended and merged with other declarations, and type aliases can also name unions and arrays. A top-level array or value is always written as a type alias, because an interface cannot describe it. You can also add export, make properties and arrays readonly, write Array<T> instead of T[] and put nested types inline.
How are null values and missing keys typed?
By default a key that held null is typed T | null, which matches what JSON.parse returns. You can make such keys optional instead (key?: T); that describes the data after nulls are removed, because JSON.parse still returns null. Keys missing from some objects are written key?: T, or key?: T | undefined for projects that use exactOptionalPropertyTypes. A key that was null in every sample is typed null, and a note asks you to replace it.
What do the comments about ISO 8601 dates and 2^53 mean?
JSON has no date type, so a value such as "2026-11-17T09:30:00Z" stays a string. The comment // ISO 8601 date-time is added only when the key holds nothing but such strings (and nulls), each a real calendar date or date and time in ISO 8601 form, so you can decide whether to convert it. Integers above 9,007,199,254,740,991 (2^53 - 1) cannot be held exactly in a JavaScript number: JSON.parse reads 12345678901234567890 as 12345678901234567168, and the comment shows this. Keep such IDs as strings.
How are the type names chosen?
Names come from keys in PascalCase, so user_profile becomes UserProfile. Array items take the singular of the key's last word: users gives User, categories Category, addresses Address and statuses Status. A word that is not a clear plural gets Item added instead, as in data and DataItem or status and StatusItem. Objects with exactly the same keys and types share one declaration. When two different objects would share a name, the second is prefixed with its parent's name (UserAddress) or numbered, and built-in names such as Date, Promise or Event are never reused, so a top-level date key gives RootDate.
Do the generated types check my data when the code runs?
No. TypeScript types are removed when your code is compiled, so they describe the data you expect without checking it. They are also inferred from your sample, so a value the sample never showed, such as a null in a key that was always a string, is not in them. For data from outside your app, check it at runtime with a schema validator such as Zod or Ajv, and use these interfaces as a starting point.
Is my JSON uploaded, and how large can it be?
Nothing is uploaded. Parsing and type inference run in your browser, and documents over 100,000 characters or with more than 1,000 objects are converted in a background worker so the page stays responsive. The limits are 5 MiB (5,242,880 bytes) of JSON and 128 levels of nesting. Only your option choices are saved, in this browser's local storage under zutilium:json-to-typescript; the JSON itself is never stored.