Free TypeScript Utility

JSON to TypeScript Converter

Generate TypeScript interfaces and type aliases from a JSON example. Inspect inferred fields, nested objects, arrays and union types, then copy or download the code.

Free to use Runs in your browser No account required Mobile friendly

Convert JSON to TypeScript

Paste a representative JSON response or load the example. The generated types describe the sample you provide, so include realistic examples for the most useful inference.

Input is parsed locally in this page. Avoid pasting passwords, access tokens or confidential production data into websites.

Example: ApiResponse, UserProfile or Product.

Generation option

Useful when building a partial-update type. Fields missing from some objects in an array are inferred as optional automatically.

Important: inferred types describe the JSON sample, not every possible API response. TypeScript types do not perform runtime validation by themselves.

Example: JSON input and TypeScript output

This sample contains primitive values, a nested object, an array of objects and a nullable field. The tool creates separate interfaces for nested structures and marks array fields optional when a key is absent from some sample objects.

Example JSON

{
  "id": 101,
  "name": "Ayesha",
  "profile": { "city": "Karachi" },
  "projects": [
    { "name": "Dashboard", "stars": 12 },
    { "name": "API Client", "stars": 8, "private": false }
  ]
}

Representative TypeScript output

export interface Profile {
  city: string;
}

export interface Project {
  name: string;
  stars: number;
  private?: boolean;
}

export interface Root {
  id: number;
  name: string;
  profile: Profile;
  projects: Project[];
}

The exact output depends on your JSON input and the root name you choose. Use the live converter above to generate types from your own example.

Practical Guide

How to Convert JSON to TypeScript Interfaces

JSON is a common format for API responses, configuration files and data exchanged between applications. TypeScript adds static type information to JavaScript projects. A JSON to TypeScript converter helps turn a representative JSON object into interfaces or type aliases, making it easier to describe the shape of data in an editor and catch certain mistakes while coding.

Why generate TypeScript types from JSON?

When an API returns nested objects, arrays, strings, numbers and boolean values, manually writing every interface can take time. Generating a first draft from a sample response gives you a starting point. You can then review names, optional fields, unions and application-specific rules before using the types in a project.

How to use this online JSON to TypeScript tool

  1. Copy a representative JSON object or array from a safe test response.
  2. Paste it into the JSON input field. The input must be valid JSON with double-quoted property names.
  3. Set a useful root name, such as ApiResponse or UserProfile.
  4. Select Generate TypeScript and review the generated interfaces and type aliases.
  5. Copy the code or download it as a .ts file, then adjust it to match your application requirements.

How nested objects, arrays and optional fields are inferred

Nested JSON objects can become separate named interfaces, while arrays receive a type based on their elements. If objects in the same array have different keys, keys missing from some sample objects are marked optional. Mixed values can produce union types such as string | number. An empty array has no element information to infer, so its element type is shown as unknown.

A single sample cannot reveal every possible value or tell whether every field will always be present. Provide several representative array items where possible, and review the generated code instead of treating inference as a complete API specification.

TypeScript types are not runtime validation

TypeScript checks types during development and compilation, but the type declarations are not automatically enforced on JSON received from an external API at runtime. If data is untrusted, validate it at the application boundary using appropriate runtime validation logic or a schema-based validator.

Related CSV and JSON developer tools

Before generating types, you may want to inspect or clean up your sample with the JSON Formatter and Validator. If your data is in a spreadsheet export, use CSV to JSON or the CSV Viewer. You can compare API samples with JSON Diff & Compare, or transform data with JSON to YAML, JSON to XML, JSON to TOML, JSON to CSV and JSON to TSV.

Frequently Asked Questions

Is this JSON to TypeScript converter free?

Yes. You can generate, copy and download TypeScript code for free in your browser.

Does the converter send my JSON to a server?

The conversion itself runs locally in your browser. The website uses analytics and diagnostics for general usage information, so do not submit passwords, tokens or confidential production data.

Can it convert JSON arrays and nested objects?

Yes. The generator infers array element types, nested interfaces and union types from the provided sample.

Why are some generated properties optional?

When objects in an array do not all contain the same key, the generator marks that property optional. You can also choose to make every property optional.

Does generated TypeScript validate API responses at runtime?

No. Type declarations help with compile-time checks but do not automatically validate incoming JSON at runtime.

What if my JSON is invalid?

The tool shows a parsing error. You can check and format the input with the JSON Formatter, then try again.

Continue working with your data using these existing tools in the same toolkit.

Browse all CSV & JSON developer tools →

Related Developer Tools

Document and inspect the structure of the JSON sample used to generate TypeScript types.