JSON → TypeScript

Generate TypeScript interfaces or types from a JSON sample.

Private by design. Your input never leaves this browser. Conversions run locally on your device.

What this tool handles

  • Emits an interface or a type alias, named from the root type name you choose.
  • Nested objects become their own named interfaces rather than inline literals.
  • Unknown and mixed types are written as unknown or any, whichever you select.
  • Types describe the sample you paste: a field that is never null in the sample is not optional.

Example

JSON sample

{"id":1,"name":"Ada","address":{"city":"London"},"tags":["a","b"]}

TypeScript

export interface Address {
  city: string;
}

export interface Root {
  id: number;
  name: string;
  address: Address;
  tags: string[];
}

When you would use it

  • Typing an untyped third-party API — Paste one real response from a service that ships no types and you get an interface tree to code against, instead of scattering any across the call site.
  • Regenerating types after a schema change — When a response grows or loses a field, generate again from a fresh sample and diff the two files to see exactly what moved.
  • Typing a captured test fixture — A payload saved as a fixture can be typed from itself, so the day the fixture drifts from the shape the test expects, the compiler says so.
  • Naming the types in a nested payload — Array elements are named from the singular of their key, so users gives a User interface. A sample that is a top-level array gives an element interface plus an exported alias for the array.

Common questions

How does it decide a field is optional?

Only by comparing records in an array: a key present in some elements and missing from others gets a question mark. A single object offers no such evidence, so every key comes out required.

What happens with an array of mixed types?

The element types are merged into a union and parenthesised, so [1, "a", true] becomes (number | string | boolean)[]. An empty array has nothing to observe and becomes unknown[], or any[] if you switch the fallback.

What type does a null field get?

A key that is null in every record is typed null and nothing more, because the sample carries no other information about it. A key that is null in one record and a string in another comes out as string | null.

Can it tell a date string from an ordinary string?

No. An ISO 8601 timestamp is typed string rather than Date, and whole numbers and decimals are both number, since TypeScript has no separate integer type.

Related tools

Browse all 25 tools