Skip to main content
Data helpers100% FreeInstant

JSON to TypeScript: Generate Interfaces from JSON

This free converter reads a JSON sample and writes TypeScript interfaces for it. It handles nested objects, arrays, null values and optional fields, and names each interface from its key.

By Debmedia Technologies LLP · Kolkata, India · Updated

What Is It and When Do You Need It?

Writing TypeScript types by hand for an API response is slow. A converter reads a real sample and writes the types for you, including nested objects, which you then tidy up.

Paste a JSON sample and copy the generated types.

How to Use This Tool

  1. Paste valid JSON.
  2. Optionally name the root type.
  3. Choose interface or type.
  4. Press Convert and copy the result.

How the Calculation Works

The tool walks the JSON. Strings, numbers and booleans become string, number and boolean. Null becomes null. Objects become named interfaces, using the key name in PascalCase. Arrays of objects are merged into one interface with optional keys where needed. Arrays with mixed items become unions.

Worked Example

The JSON {"id": 1, "tags": ["a"]} gives an interface Root with id: number; and tags: string[];.

Common Uses

  • Typing API responses.
  • Config files.
  • Mock data.
  • Migrating JavaScript to TypeScript.

Tips and Common Mistakes

  • Use a sample with every field present.
  • Review numbers that may be strings in other responses.
  • Check dates, which JSON stores as strings.
  • For arrays, include several different items in your sample so the tool can see which fields are optional and which values can be null.

Next, you may need the SQL IN clause generator, string escape tool, query string parser, Markdown table generator.

Everything runs in your browser. Nothing you type is uploaded, stored or sent to any outside service.

Frequently Asked Questions

When an array holds several objects, a key that is missing from some of them becomes optional (marked with a question mark).
As a union, for example (string | number)[].
It describes the sample you gave. Real data may have other shapes, so review the types before use.
Yes. Choose the keyword in the list.

Disclaimer: results are calculated in your browser from the numbers you enter. Check important results before you rely on them for money, health, safety or legal decisions.