JSON to TypeScript.

Generate clean TypeScript interfaces (or type aliases) from any JSON sample — with named nested types, optional-field detection, and readonly support. Instant and 100% private, in your browser.

No signup · No uploads · No file-size cap

TypeScript

Convert JSON to TypeScript online

A JSON to TypeScript converter turns sample JSON into TypeScript interfaces or type aliases. Paste an API response, webhook payload, config object, or mock JSON above and generate clean types with nested names, optional fields, readonly support, and custom root naming.

How to convert JSON to TypeScript in three steps

  1. Paste a JSON sample — ideally an array of several records, not just one.
  2. Choose your options — interface or type alias, root name, optional-field detection, readonly.
  3. Copy the types straight into your codebase.

What the generated types look like

This JSON:

[
  { "id": 1, "name": "Ada", "email": "ada@example.com",
    "address": { "city": "London", "zip": "E1 6AN" } },
  { "id": 2, "name": "Alan", "address": { "city": "Cambridge" } }
]

produces:

export interface Address {
  city: string;
  zip?: string;          // absent from the second record
}

export interface User {
  id: number;
  name: string;
  email?: string;        // absent from the second record
  address: Address;      // nested objects become named interfaces
}

export type Users = User[];

Note what a single sample would have missed: both email and zip would have been marked required, and the first time the API omitted one your code would break. That is why the generator compares across records.

Generate interfaces from realistic JSON samples

The best JSON to TypeScript interface output comes from realistic examples. Arrays help detect optional fields, nested objects become named shapes, and null values can be represented explicitly so your frontend, backend, or SDK code gets safer autocomplete.

The practical rule: paste at least three or four records that differ from one another — one with nulls, one with missing optional fields, one fully populated. Types inferred from a single happy-path response are the main reason generated types are wrong in production.

Types are not validation — the mistake worth avoiding

TypeScript types are erased at compile time. They do not exist when your code runs, so they cannot check what an API actually sends you. Declaring const user: User = await res.json() tells the compiler to trust you — it verifies nothing at runtime. If the server returns null where you promised a string, your code crashes exactly as it would have without types.

Types catch mistakes in your code; they do not police incoming data. For that you need a runtime check — generate a JSON Schema from the same sample and validate against it, or use a library like Zod. Use both together: the types for autocomplete and compile-time safety, the schema for the network boundary.

Common problems (and fixes)

“Everything came out required.” You pasted a single object. Paste an array of varied records so optional fields can be detected.

“I got any[] for an empty array.” An empty array carries no type information — nothing can infer the element type from []. Include at least one populated item.

“A field is typed null.” The only sample value was null. Add a record where the field is populated, and you will get a proper string | null union.

“My JSON will not parse.” Clean it first with the JSON repair tool or the JSON validator.

Why use this JSON to TS converter?

It is instant, private, and focused on practical TypeScript output. Use it when wiring up a new API response, documenting sample data, or replacing loose any types — and because it runs entirely in your browser, you can safely paste real API responses containing customer data or tokens, which you should never paste into a server-side generator. Need a validation contract too? Try the JSON Schema generator. Related: JSON formatter, JSON viewer to explore the shape first, and mock JSON generator to create test fixtures that match your new types. Read how to convert JSON to TypeScript.

FAQ

JSON to TypeScript, answered.

How do I convert JSON to TypeScript online? +

Paste a JSON sample into the converter, choose interface or type alias output, set a root type name, and generate. The tool infers TypeScript types from objects, arrays, strings, numbers, booleans, nulls, and nested data.

Can it generate TypeScript interfaces from JSON? +

Yes. You can generate TypeScript interfaces from JSON, including named nested interfaces. This is useful for API responses, webhook payloads, mock data, and config objects.

Can I generate type aliases instead of interfaces? +

Yes. The converter supports both TypeScript interfaces and type aliases, so you can match the style used in your codebase.

How does it detect optional fields? +

When your sample is an array of objects, the tool compares keys across rows. Fields that appear in some objects but not others can be marked optional with the ? modifier.

How are null values handled? +

Null values can be represented as union types such as string | null, or handled with the null-as-optional option depending on how your API represents missing data.

Is my JSON uploaded when generating TypeScript? +

No. JSON to TypeScript conversion is 100% client-side. Your sample is parsed and converted locally in your browser and is never uploaded or stored.

Should I use an interface or a type alias? +

For object shapes from an API, either works and the choice is stylistic. Interfaces support declaration merging and produce clearer error messages, which is why many teams default to them for data models. Type aliases are needed for unions, intersections, and mapped types. Pick whichever matches your codebase and stay consistent — the generator supports both.

Why are my types wrong for fields that are sometimes null? +

Because a single sample cannot show you what the API does over time. If one response has "middleName": null and another has a string, a type inferred from just one of them will be wrong. Paste an array of several representative records instead of one object — the generator compares across them, marks inconsistent fields optional, and produces union types like string | null.

How do I get TypeScript types from an API response? +

Call the endpoint, copy the JSON response body, and paste it here. Paste several responses as an array if the shape varies. The generated interfaces give you compile-time safety immediately — but remember they describe the sample you pasted, not a contract the server promises to keep, so validate at runtime for anything critical.

Do the generated types validate my data at runtime? +

No, and this is the most important thing to understand. TypeScript types are erased at compile time — they are not present when your code runs, so an API returning the wrong shape will still crash you. Types catch mistakes in your own code; they do not check incoming data. For runtime validation, generate a JSON Schema instead, or use a library like Zod.