Free tool JSON to TypeScript converter for API responses
Turn an API response, config file or log lines into readable types, with nested declarations, merged array items, optional keys and unions.
- Nested declarations
- Merges array items
- Runs locally
Paste JSON, copy the types
The sample is a user with two orders. Replace it with your own; the types update as you type.
Saved to My tools
Open the free tools page next time and it is right at the top under My tools (stored in this browser only).
You can also press Ctrl+D to bookmark this page in your browser.You can also press ⌘+D to bookmark this page in your browser.You can also tap your browser’s Share button (at the bottom in Safari) and choose Add Bookmark or Add to Home Screen.You can also open the ⋮ menu at the top right and tap ☆ to bookmark it, or choose Add to Home screen.You can also tap ··· at the top right and choose Favorite, or open it in your browser and bookmark it there.
View My toolsOne document, or several separated by new lines (JSON Lines); several are merged. Up to 1 MB.
export interface User {
id: number;
name: string;
email: null;
roles: string[];
orders: Order[];
}
export interface Order {
id: string;
total: number;
coupon?: string;
items: Item[];
}
export interface Item {
sku: string;
qty: number;
note?: string;
}
Declarations
3
interface and type blocks.
Properties
12
Across all declarations.
Optional
2
Marked with a question mark.
Review these
- CheckOnly null was seen for email. Replace it with the real type, such as string | null.
Done here? Try these next
Use this tool often? Save it to My tools.Saved to My tools. Find it any time at the top of the free tools page. You can also press Ctrl+D to bookmark this page in your browser.You can also press ⌘+D to bookmark this page in your browser.You can also tap your browser’s Share button (at the bottom in Safari) and choose Add Bookmark or Add to Home Screen.You can also open the ⋮ menu at the top right and tap ☆ to bookmark it, or choose Add to Home screen.You can also tap ··· at the top right and choose Favorite, or open it in your browser and bookmark it there.
Problem or suggestion?Send feedbackChat with support
Version v1.0Updated Update history
How each rule was applied
The converter only knows your sample. These rules turn what it saw into types.
- interface or type
- Optional keys inferred from arrays
- Syntax errors with line and column

Optional keys
When several objects share a position, such as the two orders, a key missing from any of them gets ?. In the sample that is coupon and note.
null
A value that is null stays in the union, for example string | null. A field that was only ever null is typed null and listed for review.
Arrays
All items are merged into one element type. Arrays of mixed kinds become a union in parentheses, such as (string | number)[].
Names
Nested types are named after the key in PascalCase, singular for array items. A clash with a different shape gets the parent name in front.
Dictionaries
An object such as {"1001": …, "1002": …} is a lookup table, not a fixed shape. With the option on it becomes Record<string, Item> instead of one property per ID.
Reused shapes
Two nested objects with exactly the same properties, such as billing and shipping addresses, share one declaration. Turn the option off if you expect them to diverge.
Types describe your sample, not the API contract. A field that never happened to be missing will look required, so paste a few varied records or check the documentation.
From response to typed code
Copy, paste, name, done.
-
1
Copy a response
From the network tab, an API client or a log file. Several records on separate lines give better optional and union detection.
-
2
Name the root
Use the name your code expects, such as
UserorOrderList. -
3
Pick the style
interface or type, export, readonly, inline nesting.
-
4
Copy or download
Take the code or save
types.ts, then tighten the notes: replace lone nulls and unknown arrays.
JSON values and the types they become
The full set of rules is short.
- JSON has no integer or date types, so numbers become
numberand ISO timestamps staystring - An empty object becomes
Record<string, unknown> - Keys that are not valid identifiers are quoted, such as
"content-type" - Names that would collide with built-ins such as
Eventget aDatasuffix
| JSON sample | TypeScript |
|---|---|
"abc", 12.5, true | string, number, boolean |
[1, 2] | number[] |
[1, "a"] | (string | number)[] |
[] | unknown[] |
"x" in one record, null in another | string | null |
| key present in some records only | key?: … |
The sample user, step by step
The sample produces 3 declarations with 12 properties, 2 of them optional.
| Field | Seen in the sample | Generated | Why |
|---|---|---|---|
User.email | null | null | No other value to learn from; flagged for review |
User.roles | "admin", "editor" | string[] | All strings |
Order.total | 49.5, 120 | number | JSON has one number type |
Order.coupon | first order only | coupon?: string | Missing from the second order |
Item.note | one of two items | note?: string | Items from both orders are merged |
Where generated types mislead
Check these before you rely on the output.
One record only
With a single object nothing can look optional or nullable. Paste a list with the awkward cases.
Trusting types at runtime
TypeScript types vanish after compiling. Validate external data with a schema or checks.
IDs as numbers
Snowflake-style IDs exceed safe integers and get rounded. Ask the API to send them as strings.
JavaScript object syntax
Trailing commas, single quotes and comments are not JSON. The error shows the line; the JSON formatter can repair them.
Event payloads that keep their shape
Events sent to TapCub carry their properties as JSON, from the web script, the app and mini-program SDKs, or the server API.
Data-quality checks
Unexpected event names, missing properties and wrong types are flagged; duplicates can be merged or renamed.
Learn moreCustom events and properties
Track orders, sign-ups or any business action with the fields you care about, then chart and filter by them.
Learn moreSDKs and server API
Seven platform SDKs plus a server API with a Server Key, all sending into one project with shared event names.
Learn moreJSON to TypeScript questions
Still have a question?
Chat with the team behind TapCub — we usually reply within a few hours on business days.
How do I convert JSON to a TypeScript interface?
Paste the JSON and set the root name. The converter writes one interface for each nested object; copy the code into a .ts file.
Should I use interface or type?
Both describe object shapes. Interfaces can be extended and merged by declaration; type aliases can also name unions and arrays. Follow your project’s convention.
How are optional properties decided?
If several objects appear in the same place and a key is missing from at least one, it becomes optional. A single object gives no evidence, so everything is required.
What happens to null values?
null is kept in a union, such as string | null. With strict null checks that forces your code to handle it.
Why do I get a syntax error?
JSON does not allow trailing commas, comments, single quotes or unquoted keys. The tool shows the line and column where parsing stopped.
How are dates typed?
As string. JSON has no date type, and converting them to Date would be wrong unless your code parses them. Change the type by hand after you add the parsing step.
Can I paste several records?
Yes. Separate documents with new lines, or paste an array. They are merged, which improves optional and union detection.
Is my data uploaded?
No. Conversion happens in your browser and the page has no share link. Still remove tokens and personal data before pasting into any online tool.
Is this tool working for you?
Rate it, or tell us what went wrong and what you’d like improved. A person reads every message, and frequent requests go into the next update.
Need help right now?
Chat with our support team, best for urgent problems; you can leave a message when we are offline.
Chat with supportUpdate history
New features, fixes and data refreshes for this tool, newest first.
-
· v1.0
LaunchedFirst release.
Missing something or found an error? Tell us — requests that come up often go into the next update. All tool updates
Recommend this tool in an article or on your site
This tool is free to cite and share. Copy the URL or link below into your article, tutorial or resource page; to write a review, embed a tool or partner with us, get in touch.
https://tapcub.com/tools/json-to-typescript<a href="https://tapcub.com/tools/json-to-typescript">JSON to TypeScript - TapCub</a>Check the data as well as typing it
Types help your editor; a schema catches bad data at runtime.