JSON to TypeScript Interface Generator

Developer Tools

Paste a JSON sample and get TypeScript interfaces or type aliases for it, nested objects included.

Options
JSON sample
TypeScript

Processed in your browser. A copy of each run is saved to your past runs so you can reopen it. Privacy

About

What the JSON to TypeScript Generator does

The JSON to TypeScript Generator infers TypeScript declarations from example JSON. Nested objects become their own named interfaces, arrays get element types, and several samples, such as the items of an array or JSON Lines, are merged so fields missing from some become optional. Choose interface or type, export and readonly, how null is written, and T[] or Array<T>.

Steps

How to use it

  1. 1Paste a JSON object, an array of objects or JSON Lines.
  2. 2Set the root name, for example User.
  3. 3Choose interface or type and the other options.
  4. 4Press Generate and copy the declarations into your code.

Example

A real run

Input

{
  "login": "octocat",
  "id": 583231,
  "name": "The Octocat",
  "site_admin": false,
  "plan": {"name": "pro", "private_repos": 9999},
  "followers": 4021
}

Output

export interface User {
  login: string;
  id: number;
  name: string;
  site_admin: boolean;
  plan: Plan;
  followers: number;
}

export interface Plan {
  name: string;
  private_repos: number;
}

The nested plan object becomes its own Plan interface. Paste several user objects at once and fields missing from some of them become optional.

Options

Every setting, and when to use it

Declare as interface or type
Interfaces are the common choice for object shapes and can be extended or merged. Type aliases suit codebases that prefer type everywhere or will combine shapes with unions.
null values
| null writes company: string | null when a sample has null. Optional writes company?: string, matching APIs that leave the key out instead of sending null.
Arrays, export and readonly
T[] and Array<T> mean the same thing; pick your lint style. export makes each declaration importable; readonly marks every property as read-only, useful for API responses you never mutate.

Good to know

Common problems and limits

Input up to 5 MB. Types are inferred from the samples, not from a contract: a field that is a number in every sample is typed number even if the API sometimes sends a string.

A field that is null in every sample is typed null with a note, because its real type cannot be inferred. Keys that are not valid identifiers, such as created-at, are quoted.

For validation rules rather than types, generate a schema with the JSON Schema Generator from the same sample.

Audience

Who uses it

  • Front-end developersType an API response before writing the fetch code, instead of typing interfaces by hand from documentation.
  • Node.js developersAdd types for webhook payloads, config files or third-party JSON that has no published type definitions.
  • Teams adopting TypeScriptGive existing JSON fixtures and mock data types, then refine them by hand; check a messy fixture first with the JSON Validator.

FAQ

Frequently asked

Should I use interface or type?

For plain object shapes both work. Interfaces can be extended with extends and merged by declaring them twice, and their errors are often easier to read. Type aliases can also name unions, tuples and mapped types. Many teams use interface for objects and type for everything else; follow your codebase.

What is the difference between optional and | undefined?

name?: string means the key may be missing. name: string | undefined means the key is always present but may hold undefined. They behave the same unless exactOptionalPropertyTypes is on, so generated types use ? for fields that are missing from some samples.

How are nested objects and arrays typed?

Each nested object becomes its own interface named after its key, so "plan" becomes Plan, and arrays of objects are named after the singular of the key, so "emails" becomes Email. Identical shapes share one declaration.

Can I import a JSON file directly as a type?

Yes, with resolveJsonModule enabled in tsconfig: import data from "./user.json" gives a typed value, and typeof data is its type. That type is exact to that one file, though; generated interfaces are named, reusable and easy to edit.

Does it generate Zod schemas or runtime validation?

No. TypeScript types disappear at runtime, so they cannot check data coming from an API. For runtime checks, use the generated interfaces as a starting point for a validation library, or generate a JSON Schema from the same sample.

Is my JSON sent anywhere?

No. The types are inferred in your browser. A copy of each run is saved to your past runs so you can reopen it, as described on the Privacy page.

Automation: an MCP tool json_to_typescript(json, options) → ts and an n8n node are planned for this tool.

GuideJSON, YAML, TOML and XML: which format when →When to use JSON, YAML, TOML or XML: what each is good at, the traps (YAML's no, JSON's big numbers, XML attributes) and how to convert between them.
Built and maintained by Radhika SinghLast updated Questions: hello@operativez.ai