๐Ÿ”’ Runs in your browser โ€” nothing is uploadedโœ“ Free, no signup

JSON to TypeScript Interface Generator

Paste JSON โ€” like an API response โ€” to generate TypeScript interfaces instantly. Nested objects, arrays, optional fields and unions are handled for you.

Loading...
Loading...

When should you use the JSON to TypeScript?

  • Typing an API response in a React, Next.js or Node.js project
  • Creating types for a config file or fixture data
  • Documenting the shape of a JSON payload for your team

How to use the JSON to TypeScript

  1. 1

    Paste JSON

    Paste an object or array into the left editor, or click Load sample.

  2. 2

    Name the root type

    Change Root to something meaningful, such as User or ApiResponse.

  3. 3

    Pick a style

    Choose interface or type, and whether to export the declarations.

  4. 4

    Copy into your project

    Use Copy Output and paste into a .ts file.

Examples

Array items with an optional field

JSON

{
  "orders": [
    { "id": 10, "total": 9.5 },
    { "id": 11, "total": 20, "coupon": "SAVE" }
  ]
}

TypeScript

export interface Root {
  orders: Order[];
}

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

Common errors and how to fix them

Invalid JSON
The input must be valid JSON. Use the JSON Validator to find the error, or the JSON Formatter's Fix JSON button to repair it.
A field should be optional but isn't
The generator only knows what's in your sample. Include an example item where the field is missing, or add ? by hand.
Related tools:ย JSON Formatter ยท JSON Schema Generator ยท CSV to JSON Converter

More from JSON Tools

Free tools that run in your browser โ€” no signup, nothing uploaded.

JSON to TypeScript FAQ

Paste a JSON object or array โ€” for example an API response โ€” and TypeScript interfaces appear instantly. Nested objects become their own named interfaces.

All objects in the array are merged into one interface. If a key appears in only some items, it's marked optional with ?. If a key has different types across items, it becomes a union like string | null.

Both work for describing object shapes. Interfaces can be extended and merged, and are the common default; type aliases are needed for unions. Tick 'Use type instead of interface' if your codebase prefers type.

The generator can only see your sample. A field that's null everywhere becomes null, and an empty array becomes unknown[]. Paste a sample where those fields have real values, or edit the types afterwards.

Keys that aren't valid TypeScript identifiers are quoted, for example "zip-code": string.

No. Types are generated in your browser, so it's safe to paste real API responses.