How to Convert JSON to TypeScript Interface: Steps and a Worked Example

By 1 min read

Generate a TypeScript type from a sample JSON object. This guide shows what to enter, a worked example, and the limits to keep in mind. The JSON to TypeScript Interface tool is free, needs no account and runs in your browser.

What you need

  • JSON, for example {"id":42,"name":"Ana","active":true,"roles":["admin"]}

Step by step

  1. Open the JSON to TypeScript Interface tool.
  2. Fill in JSON.
  3. Read the result, which updates as soon as the inputs change.

Worked example

With these inputs:

  • JSON: {"id":42,"name":"Ana","active":true,"roles":["admin"]}

the tool returns:

export type Root = { id: number; name: string; active: boolean; roles: string[] };

How it works

Paste a representative JSON object. Field types are inferred from the sample values.

Things to keep in mind

Check your inputs, units and any local rules before you rely on the result.

If this is not quite what you need, try JSON to TypeScript Type, JSON Formatter or JSON Validator.

More from the blog