JSON to TypeScript Interface

Paste any JSON and get clean TypeScript interfaces — nested objects, arrays, and all.

About This Tool

This tool converts any valid JSON object into TypeScript interface or type definitions. It recursively walks your JSON tree, generating named interfaces for every nested object and correctly typing arrays of primitives and arrays of objects.

100% client-side — your data never leaves your browser.

Supported Types

Primitive types

  • string — from JSON strings
  • number — from integers and floats
  • boolean — from true/false
  • null — from null values

Complex types

  • Nested objects → named interfaces
  • Arrays of objects → InterfaceName[]
  • Arrays of primitives → string[], etc.
  • Empty arrays → unknown[]

Options Explained

Root Interface Name

Sets the name of the top-level interface. Nested interfaces are named from their JSON key, auto-converted to PascalCase.

Output Mode

interface uses the interface keyword (best for most cases). type alias uses type Name = {...}, which is needed for certain TypeScript patterns like mapped types.

Field Separator

Semicolons are the TypeScript convention for interfaces. Commas mimic object literal style — both are valid.

Optional Properties

Adds ? to all fields, making them optional. Useful when your JSON might have missing fields in practice.

Example

JSON Input

{
  "user": {
    "id": 1,
    "name": "Alice"
  },
  "tags": ["admin"]
}

TypeScript Output

interface User {
  id: number;
  name: string;
}

interface Root {
  user: User;
  tags: string[];
}

Common Use Cases

  • API integration: Generate types from REST API responses instantly
  • Database models: Convert JSON schema to TypeScript interfaces
  • Config typing: Type your JSON config files for IDE autocomplete
  • Third-party data: Type payloads from external services quickly
  • Learning TypeScript: See how JSON maps to TypeScript types

Frequently Asked Questions

What is a TypeScript interface and why do I need one?

A TypeScript interface is a type definition that describes the shape of an object — its property names and their types. You need one whenever you want type safety, IDE autocomplete, and compile-time error checking when working with structured data like API responses or JSON config files.

What is the difference between interface and type in TypeScript?

Both describe object shapes. interface supports declaration merging and is preferred for public APIs and class contracts. type is more flexible — it supports union types, intersection types, and mapped types. For plain JSON objects, either works; use the toggle to match your project's style.

Does this tool handle deeply nested JSON?

Yes. The converter recursively walks the entire JSON tree, generating a separate named interface for every nested object. Nested interfaces are named from their JSON key converted to PascalCase, so a key user_profile becomes UserProfile.

Why does my null field get typed as null instead of the real type?

When a JSON value is null, there is no runtime information about what type it will hold when populated. The tool faithfully maps it to null. You can manually widen it to a union like string | null after copying the output.

What happens with arrays of mixed types?

The tool infers the array type from the first element. If your array contains mixed types (e.g., strings and numbers), the generated type will reflect the first element only. For mixed-type arrays, manually edit the output to use a union type like (string | number)[].

Is my JSON data sent to a server?

No. The entire conversion runs in your browser using JavaScript. Your JSON never leaves your device. This makes the tool safe to use with confidential API responses, internal config files, or any sensitive data.

When should I use optional properties (?)?

Enable optional properties when your JSON sample may not include all possible fields — for example, when a field is only present under certain conditions or when you are looking at a partial API response. Optional fields let TypeScript know a property may be undefined at runtime.

Can I convert a JSON array as the root?

The tool requires a JSON object ({...}) as the root because arrays alone do not carry property names. To type a root array, wrap the first element in an object, generate the interface, then use Root[] in your code.