JSON to TypeScript converter

To convert JSON to TypeScript, paste sample data below: the tool generates interfaces or types with nested objects, arrays and optional fields – or a JSON Schema. Your data stays in the browser.

Source: TypeScript Handbook – Object Types (interfaces, optional properties, readonly). Updated: .

My Toolbox

Result

Result
export interface Root { id: number; name: string; email: null; tags: string[]; address: Address; orders: Order[]; active: boolean; } export interface Address { street: string; zip: string; } export interface Order { no: number; total: number; voucher?: string; }
Summary
3 types generated from 217 characters of JSON.
Only what appears in the sample data is inferred: a field that was never null there is not detected as nullable; fields that are not in every object become optional (?).

How it is calculated

Converting JSON to TypeScript means deriving the matching types from sample data. {"id": 1, "name": "Anna"} becomes an interface with id: number and name: string. The tool reads your JSON in your browser, merges objects of the same kind and writes the types as source code – with no upload.

How it works

  1. Paste JSON into the field, for example an API response.
  2. Choose the output: interfaces, types (type) or JSON Schema. Set names, export, readonly and indentation as you like.
  3. Copy the result and paste it into your project.

How the types are built

Limits

The result is a draft: check it against the documentation of the interface, because sample data does not show every possible case.

Privacy

The JSON never leaves your browser. Next steps: format JSON, CSV to JSON or YAML to JSON.

Frequently asked questions

How do I convert JSON to TypeScript?

Paste the JSON and choose “TypeScript interfaces”: the tool generates interfaces with all fields, nested types and arrays. Copy it into your project.

Interface or type – which is better?

Both describe the same shape. Interfaces can be extended and often give better error messages; type is more flexible with unions. The tool generates either on request.

How does the tool detect optional fields?

A field that is missing in one object but present in another gets a question mark. Several objects in an array are merged for this.

Can I also generate a JSON Schema?

Yes, choose “JSON Schema (2020-12)”. The schema contains types, nested properties and the list of required fields.

Is my JSON uploaded?

No. The types are created entirely in your browser.

Sources and legal basis

As of: · Editorial policy

Related tools