JSON to TypeScript — Free Interface Generator 2026
JSON to TypeScript generator converts your JSON sample data into TypeScript interfaces instantly. Nested objects become separate named interfaces, arrays infer element types, mixed arrays produce union types, and missing keys across array items become optional fields. Paste any API response or JSON document to get ready-to-use TypeScript types.
How It Works
- Set the root interface name (default: Root)
- Paste any JSON object or array
- Nested objects become separate named interfaces
- Copy the output and use in your TypeScript project
JSON to TypeScript — Interface Generation Guide
Manually writing TypeScript interfaces for API responses is tedious and error-prone. This tool automates the process: paste your JSON response and get working TypeScript interfaces within seconds. The generator uses a depth-first traversal of the JSON document and emits a separate named interface for each unique object shape. Leaf interfaces (those with no nested object dependencies) are emitted first, so the output can be pasted directly into a TypeScript file without reordering. To explore the structure of your JSON before generating types, use the JSONPath Finder to navigate the document interactively.
How Types Are Inferred
| JSON value | TypeScript type | Notes |
|---|---|---|
"hello" | string | All JSON strings |
42, 3.14 | number | All JSON numbers |
true, false | boolean | Booleans |
null | null | Explicit null |
["a","b"] | string[] | Uniform arrays |
[1,"x"] | (number | string)[] | Mixed-type array |
{...} | InterfaceName | Named interface generated |
[{...}] | ItemType[] | Array of objects → typed |
Nested Interface Naming
Each nested object generates an interface named after its parent key, PascalCased. The key address becomes the interface Address, the key pagination becomes Pagination. Arrays of objects use the singularized key: users → User, books → Book. When multiple keys produce the same name (e.g., two different objects both named Data), the second gets a numeric suffix (Data2). The generator checks if two shapes are structurally identical and reuses the same interface name rather than emitting duplicates.
Optional Fields — Handling Sparse Data
When converting an array of objects, the converter compares the keys across all array items. Any key present in some items but missing in others is marked as optional with the ? modifier. For example, if some users have a phoneNumber field and others do not, the generated interface will contain phoneNumber?: string. This is the most common source of bugs when hand-writing TypeScript interfaces from a single API example — optional fields are invisible in a single response but cause type errors at runtime. This generator handles it by sampling all array items. After generating, validate your types against a JSON Schema using our JSON Schema Generator for an additional validation layer.
Limitations and Recommended Refinements
Since the generator infers types from a single sample, it has inherent limitations. ISO date strings like "2026-01-15T10:00:00Z" are typed as string — if you want Date, change them manually. String union types like 'admin' | 'viewer' are typed as string — if your API has a finite set of values, replace with the union. Nullable fields are typed as null only if null appears in the sample — consider adding string | null to fields that could be null in other responses. These refinements make your types more precise and help TypeScript catch more bugs at compile time.
Frequently Asked Questions
The converter parses your JSON and infers a TypeScript interface for each object shape. Strings become string, numbers become number, booleans become boolean, null becomes null, arrays become T[], and nested objects become separate named interfaces.
When converting an array of objects, the converter compares all items and marks any key that is missing from at least one item as optional (field?: Type). This handles API responses where some fields are conditionally present.
If an array contains elements of different types (e.g., strings and numbers), the converter generates a union type like (string | number)[]. Objects with different shapes produce a union of the corresponding interfaces.
Yes — the generated interfaces are a starting point based on a single sample. Review and add more specific union types, use Date for date fields, and add documentation comments for production use.
Comments