S SCHEMA.BIZ

Last updated:

JSON to TypeScript Converter

Paste a JSON example and this JSON to TypeScript converter writes the interfaces for it: one per object, named by where the object sits, with optional and nullable fields worked out from the data.

1
1

How This Works

All conversions use JSON Schema as an intermediate representation. Your JSON Example input is first read into a JSON Schema, then converted to TypeScript Interface. What a format can't express is listed under the output. All processing happens in your browser — your schemas are never sent to a server.

JSON ExampleJSON SchemaTypeScript Interface

How to use it

Paste a JSON value on the left, such as an API response or a config file. The TypeScript appears on the right as you type, and Copy or Download (types.ts) takes it away. Load Example fills in a small sample, and From switches the input to JSON Schema, TypeScript or GraphQL.

The JSON you paste stays in your browser. The converter first reads it into a JSON Schema with the same inference as the JSON to Schema Generator, then writes TypeScript from that schema. The site records which formats you converted between and a few counts, never the JSON.

Example: an order from an API

An order as an API might return it, with a nested customer and two line items. Only the second item has giftWrap:

{
  "id": "8f14e45f-ceea-467f-a8f8-43c9b6f1e2a1",
  "status": "shipped",
  "placedAt": "2026-11-03T14:22:05Z",
  "customer": { "name": "Ann Lee", "email": "ann@example.com" },
  "items": [
    { "sku": "MUG-01", "quantity": 2, "price": 12.5 },
    { "sku": "TEE-07", "quantity": 1, "price": 20, "giftWrap": true }
  ],
  "total": 45
}

Each nested object gets its own interface, named by its path: customer becomes RootCustomer, and the items of items become RootItem. The two items are merged into one interface, and giftWrap is optional because only one of them has it. A JSON value has no name of its own, so the root interface is called Root.

The converter's TypeScript Interface output:

export interface RootCustomer {
  name: string;
  email: string;
}

export interface RootItem {
  sku: string;
  quantity: number;
  price: number;
  giftWrap?: boolean;
}

export interface Root {
  id: string;
  status: string;
  placedAt: string;
  customer: RootCustomer;
  items: RootItem[];
  total: number;
}

Example: nulls and fields that come and go

One record can't show everything: a field that is null in your only sample can only be typed null. Give the converter a few varied records in an array, and it merges them:

{
  "issues": [
    {
      "number": 101,
      "title": "Fix login redirect",
      "labels": ["bug"],
      "assignee": { "login": "ann" },
      "closed_at": null,
      "html-url": "https://example.com/issues/101"
    },
    {
      "number": 102,
      "title": "Dark mode",
      "labels": [],
      "assignee": null,
      "closed_at": "2026-11-02T08:00:00Z",
      "votes": 4.5,
      "html-url": "https://example.com/issues/102"
    }
  ],
  "next": null
}

assignee is an object in one issue and null in the other, so it becomes RootIssueAssignee | null, and closed_at becomes string | null the same way. votes appears in one issue only, so it's optional. next is null in the only value there is, so it stays null: that's the field to fix by hand. The key html-url isn't a valid identifier, so it's quoted.

The converter's TypeScript Interface output:

export interface RootIssueAssignee {
  login: string;
}

export interface RootIssue {
  number: number;
  title: string;
  labels: string[];
  assignee: RootIssueAssignee | null;
  closed_at: string | null;
  "html-url": string;
  votes?: number;
}

export interface Root {
  issues: RootIssue[];
  next: null;
}

How JSON values become TypeScript types

Strings become string, booleans boolean, and every number number: TypeScript has one number type, so 45 and 12.5 type the same. An empty array becomes unknown[] and an empty object Record<string, unknown>, since there is nothing in them to infer from. An array that mixes kinds of value, such as [1, "x"], becomes (number | string)[].

Date-times, dates, emails, URLs, UUIDs and IPv4 addresses are recognized when the value really is one, but an interface can't say so: they all stay string. The formats matter when the target checks values at runtime. Switch To to Zod Schema and placedAt becomes z.string().datetime({ offset: true }); for a schema you already have, see the JSON Schema to Zod converter.

Objects always become an export interface. Anything else at the root, such as an array of records, becomes an export type alias of the array.

Does the output compile?

Both examples on this page are among the converter's compile tests. Their TypeScript output is compiled with tsc --strict, and each sample is typed as the root type, so the sample must fit the interfaces. The same tests run a corpus of awkward schemas (recursive types, enums, nullable unions, property names that need quotes) through every output format.

5 common mistakes

  1. Converting one record. Keys missing from your one sample aren't in the interface at all, and keys that happen to be null are typed null. Paste an array of several real records, or build a schema from many samples (one JSON value per line) in the JSON to Schema Generator and convert that schema here with From set to JSON Schema.
  2. Trusting the types at runtime. Interfaces are erased when the code compiles. (await res.json()) as Root checks nothing, so a changed API fails later and somewhere else. To check responses as they arrive, convert to a Zod schema and call parse.
  3. Keeping the generated names. Root, RootCustomer and RootItem say where a type sat in this sample, not what it is. Rename them with your editor's rename refactoring before other code depends on them.
  4. Expecting integers. TypeScript can't tell 45 from 45.5: both are number. If the difference matters, note it in a comment, or convert to a target that has integers, such as Zod (.int()) or Go (int64).
  5. Patching the output by hand when the API changes. Convert a fresh response and compare it with your file instead. The same input always gives the same output, so a diff shows what the API changed.

Frequently Asked Questions

Is this JSON to TypeScript converter free, and is my JSON uploaded?

It's free, with no account. The conversion runs in your browser, and the JSON you paste isn't sent to schema.biz or anyone else. The site's usage log records which formats you converted between and a few counts, as the privacy policy describes.

Why is the root interface called Root?

A JSON value has no name, so the converter calls the root Root and names nested types by their path from it. A JSON Schema with a title uses the title instead: add one to a schema and convert it with From set to JSON Schema.

How does it decide which fields are optional?

From the samples. In an array of objects, a key is required only when every object has it; otherwise it gets a ?. A key that is null in some objects and has a value in others becomes that type | null. In a single object every key is required.

Can it write type aliases instead of interfaces?

No. Objects always become interfaces; only values that aren't objects, such as a root array, become export type aliases.

Can I convert TypeScript back to JSON Schema?

Yes, in the Schema Converter: set From to TypeScript Interface and To to JSON Schema. It reads interfaces, type aliases and enums with the TypeScript compiler's parser, which downloads on first use (about 1 MB compressed).

Other converters