JSON to TypeScript
Generate TypeScript interfaces from sample JSON data.
What is JSON → TS?
The JSON to TypeScript generator infers TypeScript interface or type definitions directly from a sample JSON document, auto-generating nested types with structural deduplication so you never write boilerplate API response types by hand.
How it works
We walk the parsed JSON tree recursively and emit a TypeScript interface or type for every object shape encountered. Objects with identical key/value type patters are deduplicated into a single named type, so the output stays concise even for large documents with repeated sub-structures.
- Paste JSON sample. Drop a .json file or paste a JSON object or array — for example, a real API response from your app.
- Configure naming and style. Choose interface vs type alias, PascalCase vs camelCase, and whether to enable structural deduplication.
- Copy or download. Copy the generated .ts code to clipboard or download as a types.ts file ready to import into your project.
Examples
{ name: 'Alice', age: 30 }
Generates `export interface Root { name: string; age: number; }`.
Nested + dedup
An array of user objects with a shared address shape generates separate User and Address interfaces, each defined once.
Common mistakes
Dedup off for very large documents
With dedup disabled, repeated object shapes each get an inline anonymous type, making the output much longer.
Null vs optional fields
A field with `null` in one sample and `string` in another becomes `string | null`. The tool does not yet infer optionality from multiple samples.
Alternatives
JSON Schema Generator
Generate formal JSON Schema instead of TypeScript types.
JSON Formatter
If you only need to read the JSON, not generate types, use the Formatter.
Frequently asked questions
Does it handle nested objects?
Yes — nested objects become separate named interfaces with auto-generated names like User and Address.
Does it deduplicate shared shapes?
Yes, when dedup is enabled, objects with identical key/value-type fingerprints reuse a single type definition rather than repeating inline.