JSON to TypeScript: Stop Writing Interfaces By Hand
If you've ever copied a Stripe webhook response, a GitHub API reply, or any other JSON payload and then spent 20 minutes manually creating TypeScript interfaces for it — there's a better way.
The problem with manual interface writing
Real API responses have nested objects, arrays of mixed types, optional fields, and keys that don't follow any naming convention you'd choose. Writing interfaces manually means:
- Typing out 30+ fields from a Shopify order response
- Nesting interfaces for the
ownerinside a GitHub repo object - Guessing whether a field is
string | nullor juststring - Re-doing it every time the API adds a field
Auto-generation in 3 steps
- Make the API call and copy the raw JSON response
- Paste it into a JSON → TypeScript converter
- Copy the generated interfaces into a
types.tsfile
What the generator produces
// Input JSON:
{ "user": { "id": 1, "name": "Alice", "role": null } }
// Generated TypeScript:
export interface Root {
user: User;
}
export interface User {
id: number;
name: string;
role: unknown;
}Refining generated types
Auto-generators can only infer from what they see. Common refinements after generation:
unknown→ specific type — when a field isnullin the sample, the generator types it asunknown. Check the API docs and replace with the real type.- Optional fields — add
?for fields that don't appear in every response:note?: string - Union types — if a field can be multiple values, use a union:
status: "active" | "inactive" | "pending" - Rename root — change
Rootto something meaningful likeStripeWebhookEvent
Ready-made types for common APIs
For Stripe, GitHub, OpenAI, Twilio, Shopify, and 5 more APIs, the pre-generated TypeScript types are already available — copy the exact interfaces from the JSON → TypeScript converter sub-pages without even having to paste the JSON yourself.
To convert your own JSON payload, use the Aarunya JSON → TypeScript Converter — paste any JSON, set a root interface name, and get clean TypeScript interfaces instantly. Runs entirely in your browser.
Try the related tool
JSON → TypeScript Converter — free, runs 100% in your browser.
Open JSON → TypeScript Converter →Enjoyed this? Get notified when Pro launches.
