Skip to content

JSON → TypeScript Interface Generator

Paste JSON to auto-generate TypeScript interfaces. Splits nested objects into separate interfaces, infers union types for arrays, optional null / readonly, custom root type name.

100% Free No signup Browser-only Instant download 5 languages Dark mode
⬇ types.ts

            
        

📖 Where people get stuck

This builds a TypeScript interface from a JSON sample, entirely in the browser. The thing to keep in mind is that it can only describe the shape that appears in the sample you pasted. Optional fields, values that can be null, and unions of several types are treated as if they did not exist unless the sample happens to contain an instance of them.

Case What happens What to do
A field whose value is null If the sample only ever shows "deletedAt": null, there is no way to know what type the field really holds. You get null or any, and the type becomes a lie the moment a date string arrives. The most reliable fix is to paste a sample merged from several real records. Failing that, correct it by hand afterwards — deletedAt: string | null. With strictNullChecks on, the compiler will tell you about the ones you forgot.
An array that is empty or has one element Nothing can be inferred from [], so you get never[] or any[]. A single element is almost as bad: any field that happened to be absent from that one record simply disappears from the type. Include two or three genuinely different elements — one with the optional fields present, one without, one at the maximum length. Then remember to add ? to the properties that really are optional.
Treating the generated type as the source of truth A sample is one observation of an implementation, not the specification. Your type will not learn about a field the API adds later, and it can ship to production missing a property that merely happened not to appear in that one payload. Where an OpenAPI or JSON Schema document exists, treat that as the single source of truth and generate from it. The JSON Schema validator and OpenAPI to curl help while you get the schema into shape. For a third-party API with no schema at all, validate at the boundary the moment the data arrives — zod, valibot and the like — so a drift between type and reality does not first surface in production.

Every JSON number becomes number, but a JavaScript number cannot hold an integer beyond 253-1 (9,007,199,254,740,991) exactly. An API returning int64 IDs will silently lose digits and point at a different record. Agree with the server to return IDs as strings, or receive them as bigint. Dates behave similarly: "2026-07-26T00:00:00Z" can only be a string, so decide up front which layer converts to Date and you will not have to rewrite the types later.

❓ Frequently Asked Questions

Mixed array types?
All elements analyzed -> union type (string | number etc.)
null vs undefined?
JSON has no undefined. With option ON: field?: T. With OFF: field: T | null
Date / custom types?
In JSON they're strings, indistinguishable from Date. Manually rewrite afterwards
🐛 Found a bug or issue with this tool?

Free to use, no signup. Even just the steps to reproduce are helpful. Reports go directly to the operator and help us fix issues.

* Browser info (UA / screen / language / URL) is sent automatically to help reproduce the issue