JSON to TypeScript converter

TypeScript interfaces from JSON.

Declare as
Arrays

0 lines · 0 characters

0 lines · 0 characters

Results update as you type.

Runs in your browser. Nothing uploaded.

How to convert JSON to TypeScript

  1. Paste a JSON sample, such as an API response, into JSON, or open a .json file.
  2. Set the Root name for the top-level type, and choose interface or type, the array style and whether to export.
  3. Copy the TypeScript or download it as types.ts.

Getting accurate types from a sample

The types can only be as complete as the JSON you paste. A field that happened to be missing, an empty array or a value that’s null in your sample can’t show its real type. Paste a response with several items, so the merge can spot optional fields, and include an example where each list has at least one entry. Empty arrays become unknown[]; replace unknown with the real type once you know it.

Numbers come out as number whether they’re whole or decimal, and dates come out as string, because JSON has no date type. If your code parses dates into Date objects, change those fields after converting.

Keys that aren’t valid names

Keys with dashes, spaces or a leading digit, such as “e-mail” or “2fa”, are kept in quotes so the type still matches the data. You read them with brackets in TypeScript: user[“e-mail”].