>Fafa Dev Tools

JSON to TypeScript

Convert JSON to TypeScript interfaces instantly. Free online JSON to TS type generator with nested object support.

0 chars
Output will appear here...

What is JSON to TypeScript?

TypeScript interfaces define the shape of data objects with type annotations. Converting JSON to TypeScript interfaces automatically generates type definitions from real data, saving you from writing them by hand. This is especially useful when working with APIs — paste a sample JSON response and get a ready-to-use TypeScript interface.

How to Use

  1. Paste your JSON data (object or array) in the input area
  2. The TypeScript interface is generated instantly in the output panel
  3. Nested objects become separate interfaces with auto-generated names
  4. Optional fields are marked with ? when the input data is ambiguous
  5. Copy the generated interface code into your TypeScript project

Examples

Simple object to interface

Input{"name": "Alice", "age": 30, "active": true}
Outputinterface RootObject { name: string; age: number; active: boolean; }

Nested object with array

Input{"user": {"id": 1, "roles": ["admin"]}, "score": 95.5}
Outputinterface RootObject { user: User; score: number; } interface User { id: number; roles: string[]; }

Frequently Asked Questions

How does it determine the TypeScript types?

The tool inspects each value in the JSON and maps it to the appropriate TypeScript type: strings become string, numbers become number, booleans become boolean, null becomes null, arrays become T[], and objects become nested interfaces.

What if the JSON has mixed types in an array?

When an array contains mixed types (e.g., [1, "two", true]), the tool uses a union type (string | number | boolean)[]. When all items have the same structure, it extracts a common interface for the array items.

Can I customize the interface name?

The default interface name is RootObject for the top-level object. Nested interfaces are named based on their parent key (e.g., User for a field named "user"). You can rename them after copying into your project.