Skip to content
migration.tools
JSON to TypeScript

JSON to TypeScript converter

Migrating a JavaScript codebase to TypeScript, or consuming an API with no published types? Paste a real response and get interfaces for it, with nested objects named after their keys.

Options

JSON

TypeScript

The result appears here as soon as there is input.

Processed on this device. Nothing you paste or drop is uploaded.

How to use it

  1. 1Paste your JSON or drop a file onto the input panel.
  2. 2Adjust the options — the result updates as you type.
  3. 3Copy the TypeScript or download it. Drop several files to convert a batch into one ZIP.

How types are inferred

Every element of an array is inspected, not just the first. A key that is missing from some elements becomes optional (coupon?: string), and a key that is sometimes null becomes a union (string | null) — the two cases a single-sample generator gets wrong.

Nested objects get their own named interface, taken from the key and singularised for arrays: subscriptions: Subscription[]. Integers and decimals are both number, as they are in JavaScript.

Questions

A field is null in my sample. What type does it get?

null on its own, because the sample holds no other evidence. Paste a response where the field has a value, or edit the type by hand.

Should I use interface or type?

Either works for object shapes. Interfaces give clearer error messages and can be extended; type aliases are needed for unions. The option switches between them.