Skip to content
MoneyDeck

JSON to TypeScript

Paste a JSON sample, get clean TypeScript interfaces instantly

Updated · Free, no signup

TypeScript

export interface Root {
  id: number;
  name: string;
  email: string;
  active: boolean;
  roles: string[];
  address: Address;
  orders: Order[];
}

export interface Address {
  street: string;
  city: string;
  postcode: null;
}

export interface Order {
  id: number;
  total: number;
  items: string[];
  coupon?: string;
}

Status

Valid JSON

Types generated

3

Properties

14

  • Some properties are only ever null in the sample, so they are typed null — replace with the real type (e.g. string | null).

About the JSON to TypeScript

This JSON to TypeScript converter writes type definitions from an example payload. Paste a response from your API, a config file or a fixture, name the root type, and it produces an interface for every distinct object — nested objects become their own named interfaces, arrays become typed arrays, and mixed values become union types such as string | number.

When an array holds several objects, their shapes are merged: a key that appears in only some items is marked optional with ?, and a key that is sometimes null gets | null. Interface names come from the property names (orders → Order, categories → Category), with numbers appended if two different shapes would share a name. Choose interface or type alias syntax, add export and readonly modifiers, and copy the result into your project.

A single sample can only show the types it contains, so review the output: a field that is null in your sample is typed null, and an empty array becomes unknown[]. Conversion runs entirely in your browser, so private API data is never uploaded.

How to use the json to typescript

  1. 1Paste a representative JSON sample — include array items that show optional fields.
  2. 2Set the root type name, e.g. User or ApiResponse.
  3. 3Choose interface or type alias and the export/readonly options.
  4. 4Copy the generated TypeScript into your project.
  5. 5Review null-only fields and unknown[] arrays and tighten them by hand.

Formula and method

The JSON is parsed and every value is folded into a shape: primitives record their type (string, number, boolean, null), arrays merge all of their elements into one element shape, and objects record each key, how many times it appeared and the merged shape of its values. Merging lets one interface describe every item in an array of objects.

Each object shape becomes a named interface: the name is the PascalCase form of the property that holds it (singularised for arrays, so orders → Order), with a number appended on a clash. A key seen in fewer objects than the total is optional; several observed types become a union, with null listed last. Interfaces are emitted root first, then nested types in the order they are discovered.

Worked examples

User with nested address and orders

The root object has 7 keys, address 3 and each order 4 — 14 properties across 3 interfaces. coupon appears in only one of the two orders, so it is optional, and the empty items array in the second order is covered by string[] from the first.

Array of mixed records as type aliases

The root is an array, so Line becomes an array alias of a new LineItem type. sku is a string in one record and a number in the other, giving string | number; note is missing from the first record, so it is optional.

Keys that are not valid identifiers

Keys with hyphens, spaces or a leading digit must be quoted in TypeScript. The nested object under "meta data" gets the PascalCase name MetaData, and every property is marked readonly.

Frequently asked questions

Should I use interface or type for JSON data?+

Both describe object shapes equally well. Interfaces can be extended and merged and give slightly clearer error messages; type aliases are required for unions and mapped types. Many teams use interfaces for API models and types for everything else.

How are optional properties detected?+

Only from arrays: when several objects are merged and a key is missing from some of them, it is marked optional. A single object cannot reveal which keys are optional, so add more varied samples or mark fields optional by hand.

Why is a field typed as null?+

If a property is null in every sample, the converter cannot know its real type. Replace null with the intended type plus null, for example string | null, or provide a sample where the field has a value.

Does this validate data at runtime?+

No. TypeScript types are erased when compiled, so they do not check real API responses. For runtime validation use a schema library such as Zod, Valibot or io-ts, or generate a JSON Schema and validate against it.

How are dates handled?+

JSON has no date type, so ISO strings like "2026-01-31T10:00:00Z" are typed string. Convert them to Date objects in your code after parsing if you need date arithmetic.

Related tools