JSON to TypeScript Converter

Paste a JSON sample and get TypeScript interfaces or types. Nested objects get their own names, and fields missing from some items become optional.

Processed on your device. Files are not uploaded

How to generate TypeScript code from JSON

  1. Paste your JSON sample

    Paste or type it into the box, or press Try an example. Use a real response that has every field you expect.

  2. Name the main type

    Set the name of the top-level type, if you want something other than Root.

  3. Check the TypeScript output

    Nested objects become their own types. Rename fields or mark optional ones to suit your API.

    A field missing from your sample will be missing from the result.

  4. Use it in your project

    Paste the interfaces into a .ts file.

Worked example

This is what JSON to TypeScript Converter gives for its own sample values. Open the tool above and change anything to try your own.

JSON sample

{
  "id": 42,
  "user-name": "ada",
  "score": 9.5,
  "active": true,
  "tags": ["admin", "beta"],
  "address": { "city": "London", "zip": "N1 9GU" },
  "orders": [
    { "sku": "A-1", "qty": 2, "coupon": "SAVE10" },
    { "sku": "B-7", "qty": 1 }
  ]
}
Name of the main type
Root
Declare with
interface

Generated code

export interface Address {
  city: string;
  zip: string;
}

export interface Order {
  sku: string;
  qty: number;
  coupon?: string;
}

export interface Root {
  id: number;
  "user-name": string;
...

About JSON to TypeScript Converter

Paste a sample of your JSON and get TypeScript interfaces or type aliases. Nested objects get their own named types and fields that are missing from some items become optional. The sample can be an API response, a config file or a test fixture. When a list holds several objects they are merged, so a field that only some of them have is marked optional.

FAQs

What else can I generate from JSON?

Use JSON to Zod Schema Converter, or another converter in the JSON to code group.

Related tools