Paste your JSON below to generate TypeScript interfaces:

Loading...

Why Generate TypeScript from JSON?

TypeScript interfaces provide type safety for your JSON data. Instead of manually writing interfaces, generate them automatically from API responses or sample JSON data.

Example Conversion

Input JSON:

{
  "id": 1,
  "name": "John Doe",
  "email": "john@example.com",
  "isActive": true
}

Generated TypeScript:

interface User {
  id: number;
  name: string;
  email: string;
  isActive: boolean;
}

Features

  • Nested object support โ€” Creates separate interfaces for nested objects
  • Array type inference โ€” Detects array item types automatically
  • Custom root name โ€” Name your root interface anything you want
  • Special character handling โ€” Properly quotes keys with special characters

Type Inference Rules

JSON ValueTypeScript Type
"string"string
123, 45.67number
true, falseboolean
nullnull
[1, 2, 3]number[]
["a", 1](string | number)[]
{ ... }Separate interface

Handling Nested Objects

Nested objects automatically get their own interfaces with descriptive names:

// Input
{
  "user": {
    "profile": {
      "name": "John"
    }
  }
}

// Output
interface RootUserProfile {
  name: string;
}

interface RootUser {
  profile: RootUserProfile;
}

interface Root {
  user: RootUser;
}

Working with API Responses

Common workflow for typing API data:

  1. Make an API request and copy the JSON response
  2. Paste it into this tool
  3. Name the root interface (e.g., ApiResponse)
  4. Copy the generated interfaces to your TypeScript project
  5. Use with fetch or your HTTP client
// Usage in TypeScript
const response = await fetch('/api/users');
const data: User[] = await response.json();

// Now you have full type safety
data.forEach(user => {
  console.log(user.name); // TypeScript knows this is a string
});

Pro Tips

  • ๐Ÿ’ก Use representative data โ€” Include all possible fields in your sample JSON for complete interfaces
  • ๐Ÿ’ก Handle optional fields โ€” If a field might be missing, manually add ? after generation
  • ๐Ÿ’ก Union types โ€” For fields that can be multiple types, consider using union types manually
  • ๐Ÿ’ก Validate first โ€” Use the JSON Validator to ensure your JSON is valid before converting

Limitations

  • Cannot detect optional properties (all properties are required)
  • Cannot infer union types for non-array values
  • Date strings are typed as string, not Date

For these cases, manually adjust the generated interfaces after copying.

Related Tools