Home JSON to TypeScript

JSON to TypeScript interface generator

Paste a JSON array and get the interfaces that describe it. Nesting is kept, keys that are sometimes absent are marked optional. Review the generated declarations below.

Other languages:TürkçeDeutsch中文हिन्दीРусский

What the full sample tells you

Inference reads every record you paste. Include records with absent keys, nulls, mixed numbers and empty arrays so the generated types describe those cases.

  • Missing keys become optional. A key absent in any record can be omitted.
  • Null values remain nullable. A key can be both optional and nullable.
  • Integers and decimals share a number type. Target-specific output may distinguish them only when all observed values allow it.
  • String shapes are recognized where supported. Targets can preserve UUID, date, timestamp, email and URL annotations.
  • Empty arrays leave their element type unknown. Add representative elements before relying on the result.

The result describes the sample. Review it against your API contract before using it as a type or validator.

Nesting becomes named interfaces

Each nested object gets a named interface. In this sample, the nested user becomes User2 because the root record already uses User.

export interface User2 {
  name: string;
  email: string;
  nickname?: string;
}

export interface User {
  id: number;
  user: User2;
  tags: string[];
  score: number;
  created: string;
}

Names come from the key, so a property called user produces a User name. A collision adds a numeric suffix to keep the shapes separate. You can rename the interfaces after copying them.

Optional and nullable are different

nickname?: string means the key may be absent. nickname: string | null means the key is there and its value may be null. TypeScript treats these differently under exactOptionalPropertyTypes, and an API that returns explicit nulls is not the same as one that omits the field. Both are inferred separately, and a key that is both sometimes-absent and sometimes-null gets both.

What it does not infer

  • Literal unions. A status field holding only "open" and "closed" is typed string. Add a literal union only if your API contract defines a closed set.
  • Branded or nominal types. A UUID is string; TypeScript has no built-in for it.
  • Dates. An ISO timestamp is string, because that is what JSON.parse gives you. Convert deliberately rather than typing it as Date and being wrong at runtime.
  • Recursive shapes. A tree that nests into itself produces nested interfaces rather than a recursive one.

Common questions

Does it read the whole array or just the first object?

The whole array. Missing keys, nulls, nested shapes and numeric values are merged across all records in the input.

How are nested objects handled?

Each nested object gets a named interface. A name collision adds a numeric suffix; review or rename the interfaces before copying them into your project.

What is the difference between the ? and | null in the output?

The question mark means the key may be absent from the object. The union with null means the key is present and its value may be null. They are different things, TypeScript treats them differently, and both are inferred separately.

Why is my status field string rather than a union of its values?

The sample does not establish an exhaustive set of allowed values. Add the literal union yourself when your API contract defines one.

Is my JSON uploaded anywhere?

No. This tool processes your input in your browser without uploading it.

Last updated