About JSON to TypeScript
Generate TypeScript interfaces from any JSON sample. Handles nested objects (inline interfaces by default), arrays of objects (one unified interface), optional fields (when keys differ between array items), and union types (when a field has multiple shapes). Output is ready to paste into your codebase.
What this tool replaces
The first 30 minutes of integrating with a new API: hand-typing TypeScript interfaces from the response. Curl the endpoint, paste here, get types, paste into your codebase. Saves a chunk of every integration.
What it generates
export interface User {
id: number;
name: string;
email: string;
tags?: string[];
address: Address;
}
export interface Address {
street: string;
city: string;
state: string;
zip: string;
}
Nested objects become their own exported interfaces. Optional fields get ?. Arrays of mixed types collapse to unions.
Common workflows
Type a new API response. curl | jq → paste here → copy types → paste into src/types/api.ts. Compile-time confidence in seconds.
Update types after API change. Re-curl, re-paste, diff against existing types in Diff Checker, apply changes.
Bootstrap a new project. Have sample JSON for fixtures? Generate types from them as a starting point.
What this tool can’t infer
- Date strings vs strings — JSON has no Date type, so ISO 8601 strings type as
string. Add a brand orascast in your code. - String enums — fields with limited values type as
stringunless you flip the enum-detection toggle. - Discriminated unions across many shapes — if your data has 5 variants but the sample only shows 2, you will need to extend by hand.
For deep schema work with constraints, switch to JSON Schema Validator for runtime validation alongside the static types.
Frequently asked questions
Inline or named nested types?
How is "optional" inferred?
?). Useful when sample data covers the variation; brittle when the sample is too small.What about unions?
{ a: 1 } | { a: "x" } becomes { a: number | string }. For richer cases (different shapes), discriminated unions are produced when a field consistently differentiates the variants.Does it support readonly / strict optional?
strict tsconfig for fully immutable types.Is the JSON sent anywhere?
How big a sample?
Related tools
Last updated: 2025-01-15