JSON to TypeScript Interface Generator
Paste JSON and instantly generate TypeScript interfaces. Recursively handles nested objects, arrays, union types, and nullable fields. 100% client side.
About JSON to TypeScript Conversion
This tool analyzes the structure of your JSON data and generates corresponding TypeScript interfaces. It recursively processes nested objects and detects array element types to produce accurate, ready-to-use type definitions.
Features
- Recursively generates interfaces for nested objects
- Detects array element types (primitives, objects, mixed)
- Handles
nullvalues asany(nullable) - Converts JSON keys to valid TypeScript property names
- Custom root interface naming
How It Works
- Primitive values map to
string,number, orboolean - Nested objects generate separate named interfaces
- Arrays of objects generate item interfaces (e.g.,
ITagsItem) - Null values become
anysince the type cannot be inferred
Related Tools
- JSON Formatter - format and validate JSON
- JSON Schema Validator - validate JSON against a schema
- JSON to YAML - convert between JSON and YAML
- JSON Diff - compare two JSON documents
From JSON Sample to TypeScript Interface
Reverse-engineering a TypeScript type from a JSON example is one of the most common one-off tasks for a frontend or full-stack engineer. The API doesn't have an OpenAPI spec, the team's docs are out of date, but you have a sample response — the fastest path to compiler-checked code is generating a starter interface from that sample, then refining.
What automatic generation gets right
- Object shapes — every key becomes a property.
- Primitive types (string, number, boolean, null).
- Arrays of homogeneous primitives.
- Nested objects (recursively).
- Optional vs required (best-effort, based on which keys appear in all samples).
What it can't infer (and what you must add)
- Union types. A field that's sometimes
string, sometimesnull, sometimes missing — generators guessstring | null | undefinedbut can't know if other variants exist. - String literal unions.
status: "active"in your sample looks likestring, but the API might emit"active" | "pending" | "cancelled". You have to know the domain. - Enums. Generators don't promote literal unions to enums — you decide.
- Nullable arrays. Empty arrays
[]getany[]ornever[]depending on the tool. Always specify the element type manually. - Date strings.
"2026-05-03T12:00:00Z"looks likestring. If you parse it to a Date later, type the field asDateafter parsing. - Numeric IDs that should be branded. A type alias like
type UserId = number & { __brand: 'UserId' }prevents passing a UserId where a PostId is expected.
Workflow recommendations
- Capture multiple sample responses — one with every optional field populated, one minimal.
- Run the generator on each. Diff the results.
- Manually merge the differences into a final interface, marking optional fields with
?. - Tighten string fields to literal unions where you know the domain.
- Run your own code against the type and let the compiler surface mismatches.
- If the API is documented in OpenAPI/JSON Schema, prefer generating from that — it's authoritative.
When to use Zod or io-ts instead
For external APIs you don't control, runtime validation matters as much as compile-time types. Schema libraries like Zod, io-ts, and ArkType produce both at once: you write a schema, you get a TypeScript type AND a runtime validator. The validator catches API drift you wouldn't notice at compile time.
This generator is a starting point — not the finish line. It runs entirely in your browser, so confidential payloads stay local.
Frequently Asked Questions
How do I handle fields that are sometimes null?
After generation, change the field type to "T | null" (or add ? for optional). The generator may default to one or the other based on your samples.
Should I use type or interface?
For object shapes that might be extended, interface. For unions, intersections, or one-off shapes, type. Most modern style guides use type by default.
What if my JSON has duplicate keys with different shapes?
Standard JSON forbids duplicate keys. If your input has them, the parser keeps only the last value — review your source.
Can I generate types from a remote API?
Save a sample response to a file or paste it here. For canonical types, use the API's OpenAPI/Swagger spec with openapi-typescript instead.