JSON to TypeScript

Generate clean TypeScript interfaces from any JSON sample.

Runs in your browser Instant No sign-up
Declare as
JSON input
TypeScript

Paste, type or drop a file — output appears as you type.

Waiting for input
Processed locally · nothing is uploadedProcessed locally

How it works

Paste a JSON sample — an API response, a config file, a database row — and get TypeScript declarations you can paste straight into your codebase:

  1. Every object becomes an interface (or type), named after its property: owner → Owner.
  2. Arrays of objects are merged into one type named in the singular: tasks → Task[], categories → Category[].
  3. Properties missing from some array items become optional (estimate?: number).
  4. Mixed values become unions: [1, "a", null] → (string | number | null)[].
  5. Identical shapes are reused, so from and to coordinates share one From type instead of two copies.
  6. Keys that aren’t valid identifiers (like first-name) are quoted automatically.

Example

{
  "id": 42,
  "owner": { "id": 7, "name": "Linh" },
  "tasks": [
    { "id": 1, "done": true, "estimate": 3 },
    { "id": 2, "done": false, "assignee": "Minh" }
  ]
}

becomes

export interface Root {
  id: number;
  owner: Owner;
  tasks: Task[];
}

export interface Owner {
  id: number;
  name: string;
}

export interface Task {
  id: number;
  done: boolean;
  estimate?: number;
  assignee?: string;
}

Options

  • Root name — the name of the top-level type, e.g. User or ApiResponse.
  • Declare as — interface or type alias.
  • Export — add export so the types can be imported from other files.

Tips for better types

  • Use real responses, not hand-written samples. Capture a few responses from your API and combine them into an array so optional fields are detected.
  • Refine after generating. Narrow string to string-literal unions where you know the values (status: "open" | "closed"), and replace null with the real type.
  • Keep types next to the code that fetches the data, and regenerate them when the API changes.
  • Need runtime checks too? Generate a matching schema with JSON to Zod instead of maintaining interfaces by hand.

Common mistakes

  • Typing from one object. With a single sample, every property is required. Combine several responses into an array so fields that are sometimes missing become optional.
  • Empty arrays and objects. [] becomes unknown[] and {} becomes Record<string, unknown>, because there is nothing to infer from. Replace them once you know the real shape.
  • Mixed arrays. [1, "x"] becomes (string | number)[]. That is often a sign the API returns different shapes in different cases, so check it before narrowing the type.

If your sample isn’t valid JSON (copied from logs or an LLM), the error panel offers Fix with JSON Repair, or open JSON Repair directly. To browse a large payload before typing it, use the JSON Viewer. For backend code, the same sample produces Go structs or Pydantic models.

Frequently asked questions

How are optional properties detected?

When an array contains several objects, the generator merges them. A property that appears in some objects but not all is marked optional with `?`. Give it a representative sample — the more varied the objects, the more accurate the types.

Why is a field typed as `null`?

Because every sample value for that field was null, so there is no way to know the real type. Replace `null` with the expected type (for example `string | null`) or provide a sample where the field has a value.

Interface or type — which should I choose?

Both describe object shapes equally well. Interfaces can be extended and merged and give slightly clearer error messages; type aliases are required for unions and mapped types. Many teams simply pick one for consistency.

Does it validate data at runtime?

No. TypeScript types disappear at compile time. To validate API responses at runtime, pair these types with a schema library such as Zod, Valibot or ArkType.

Is my JSON uploaded?

No. Type generation runs entirely in your browser — nothing is uploaded.

Last updated