Tech News, Tech & Coding · Free Online Tools

IT Question Answer
Tools
Developer & Text ToolsFree100% Client-Side

JSON to TypeScript Converter

Generate TypeScript interfaces or types from a JSON sample, including nested objects and optional fields.

100% privateRuns instantly in-browserUpdated regularly

Advertisement

Runs in your browser

Your input is processed on your device and is not uploaded to our servers.

Fast

No queues and no upload wait, so results appear as soon as you act.

Clean and simple

Dark mode, no popups, and no signup.

What you get

  • Interfaces or type aliases
  • Nested objects become named interfaces
  • Optional fields from mixed array items
  • Root name and export options
  • 100% client-side

What the converter does

When you call an API, you usually get JSON and need TypeScript types for it. Writing them by hand is slow for large responses. This tool reads a JSON sample and generates TypeScript interfaces (or type aliases) for it, including nested objects, arrays and fields that are sometimes missing.

How to use it

  • Paste a JSON sample, ideally a real response.
  • Set the name of the root type.
  • Choose interface or type, and whether to add export.
  • Optionally mark null fields as optional.
  • Copy the generated code into your project.

How the types are inferred

  • Strings, numbers and booleans become string, number and boolean.
  • Nested objects become their own named interfaces, named after the property.
  • Arrays become Type[]. If array items have different shapes, they are merged and fields missing from some items become optional.
  • A null value becomes null. Mark it optional if the field can also be absent.
  • Property names that are not valid identifiers are quoted.

Example

A sample with two order records:

{ "id": 1, "name": "Asha", "orders": [{ "id": 7, "coupon": "NEW" }, { "id": 8 }] }

→

export interface Root {
  id: number;
  name: string;
  orders: Order[];
}

export interface Order {
  id: number;
  coupon?: string;
}

Important limits

The types come from your sample only. If a field can also be a number in some responses but your sample shows a string, the type will be too narrow. Use a sample with several records, check the generated code against your API documentation, and treat the result as a starting point.

Related tools

Advertisement

Frequently asked questions

Your choice. Switch between interface and type, and add export if needed.

A field that is missing from some objects in an array becomes optional. You can also mark null fields optional.

Yes. Nested objects become separate named interfaces and arrays become typed lists.

It reflects the sample you give. Review it against your real API, because one sample cannot show every possible value.

No. The types are generated in your browser.