Skip to content

JSON to TypeScript & TypeScript to JSON

Generate TypeScript interfaces from a JSON sample, or sample JSON from TypeScript types.

Input JSON

About the JSON ⇄ TypeScript

Paste a sample API response and get ready-to-use TypeScript interfaces, or swap direction to turn interfaces, type aliases and enums into realistic sample JSON. Nested objects become their own interfaces, and keys missing from some array items are marked optional.

How to use it

  1. Paste a JSON sample to generate types, or press Swap and paste TypeScript types to generate sample JSON.
  2. The result appears as you type; for TypeScript to JSON, pick which type to generate when there are several. Swap moves the result into the input so you can convert it back.
  3. Use Options for the root type name, interface or type, array style, null handling and more (or, for TypeScript to JSON, the kind of values, optional fields and array length), then copy or download the file.

Frequently asked questions

How are optional properties detected?

When an array contains several objects, any key that is missing from at least one object is marked optional with ?.

Are the types guaranteed to be complete?

Types are inferred from the sample you provide. Use a sample that includes every field and variant you expect, and review nullable fields by hand.

What does TypeScript to JSON generate?

A sample value for the chosen type: realistic values picked from property names (an email for email, a date for createdAt, a price for price), or plain placeholders. Values in @example, @default or e.g. comments are used as they are, so types made with JSON to TypeScript and Example comments give back the original values. Unions use their first member, literal types and enums their first value, and recursive types stop after one level.

Which TypeScript syntax is supported?

Interfaces with extends and generics, type aliases, enums, unions, intersections, arrays, tuples, literal and template types, index signatures, mapped and indexed access types, and utility types such as Partial, Pick, Omit and Record. Functions and methods are left out because JSON can't hold them.

Related tools