Skip to content

JSON to TypeScript Converter

Generates TypeScript interfaces from a JSON example, including nested objects, arrays, optional and nullable fields.

Your JSON stays on this device

This tool runs entirely inside your web browser. Your JSON is processed on your own device and is never sent to our servers. How this works

TypeScript

JSON to TypeScript is a free converter that generates TypeScript interfaces or type aliases from example JSON, such as an API response. It detects nested objects, arrays, optional properties and nullable values. Everything runs in your browser, so you can safely paste real data.

How to convert JSON to TypeScript

  1. Paste a JSON example into the left box. A real API response works best.
  2. TypeScript declarations appear on the right as you type.
  3. Optionally rename the top-level type, switch between interface and type, or remove export.
  4. Copy the result into your project, or download it as types.ts.

Example

{
  "id": 7,
  "owner": { "id": 12, "name": "Priya" },
  "tasks": [
    { "id": 1, "text": "Write docs", "dueDate": "2026-10-01" },
    { "id": 2, "text": "Ship it", "dueDate": null, "assignee": { "id": 12, "name": "Priya" } }
  ]
}

generates:

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

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

export interface Task {
  id: number;
  text: string;
  dueDate: string | null;
  assignee?: Owner;
}

Notice what the converter worked out from the two tasks:

Tips for accurate types

Edge cases handled

Types are not runtime validation

TypeScript types are removed when your code is compiled, so they can’t stop an API from returning unexpected data at runtime. If you need to check data as it arrives, use a validation library such as Zod alongside these types.

If your JSON has an error, the converter points it out; the JSON Validator lists every problem at once.

Frequently asked questions

How are optional fields detected?

When your JSON contains an array of objects, every object is compared. A property missing from some of them is marked optional with ?. Paste a response with several items for the most accurate types.

How are null values handled?

A value that is null in one place and a string elsewhere becomes string | null. If a field is only ever null in your sample, it is typed as null, so add a sample with a real value to get a better type.

Should I use interface or type?

Either works for describing JSON. Interfaces can be extended and merged, and many style guides prefer them for object shapes. Type aliases are needed for unions and top-level arrays. Pick whichever your project uses.

Does it check my data at runtime?

No. TypeScript types disappear when your code runs, so they cannot catch an API that returns unexpected data. For runtime checks, use a validation library such as Zod.

Is my JSON uploaded?

No. Types are generated in your browser, so it is safe to paste real API responses that contain private data.

Last updated

Missing a feature, or need a tool we don’t have? Suggest it.