tool

JSON ↔ TypeScript Interface & Type Generator

Convert JSON into clean TypeScript interfaces or turn interfaces back into JSON. This tool supports both TypeScript type aliases and interfaces, making it easy to generate.

JSONTypeScript
JSON1 lines
1
TypeScript1 lines
1

Generate TypeScript interfaces from JSON (and JSON from types)

Paste a JSON object, such as an API response or a config file, and get ready-to-use TypeScript interface or type declarations, with a separate, properly named type for every nested object. Working the other way round? Swap the direction, paste existing interfaces or type aliases and get a sample JSON object you can use as mock data, a test fixture or documentation. Conversion happens in your browser.

What can you do?

  1. 1. JSON to TypeScript interfaces
    Infer string, number, boolean, null and array types from your data and generate one interface per nested object, named after its property (address → Address).
  2. 2. Interfaces or type aliases
    Tick “type aliases” to output type Name = { … } instead of interface Name { … }, matching whichever convention your codebase uses.
  3. 3. Custom root name and export keyword
    Name the top-level type (User, Order, ApiResponse…) and optionally prefix every declaration with export so you can drop the file straight into a module.
  4. 4. TypeScript to JSON sample data
    Paste interfaces or type aliases and generate an example object with placeholder values. Referenced types are expanded, so a nested Dimensions type becomes a nested object.
  5. 5. Copy or download
    Copy the result, or download it as a .ts or .json file.

Why generate types from JSON?

Typing an API response by hand means reading every property, guessing its type and keeping nested objects straight. For a response with dozens of fields that's slow, and a single typo leaves a gap your editor can't warn you about.

Generating the interfaces from a real response gives you an accurate starting point in seconds. You then refine what a single sample can't tell you, such as which fields are optional or which strings are actually a fixed set of values.

How to convert JSON to a TypeScript interface

  1. 1. Paste a JSON object
    Use a real response from your API for the most accurate result. The top-level value must be an object.
  2. 2. Set the root name
    Replace the default Root with a meaningful name such as User or ProductResponse.
  3. 3. Choose interface or type, and export
    Leave “type aliases” off for interfaces, or turn it on for type aliases. Turn on “export” if the types will live in their own file.
  4. 4. Convert and review
    Click convert, then review the output, especially null fields and arrays, before copying or downloading it.

Example: API response to TypeScript

This customer object contains a nested object, an array of objects, an array of strings and a null value. With the root name set to Customer and export turned on, the tool produces three interfaces:

JSONJSON input
{
  "id": 101,
  "name": "Priya",
  "isActive": true,
  "address": { "city": "Chennai", "pinCode": "600001" },
  "orders": [{ "orderId": "A-1042", "total": 1499.5 }],
  "tags": ["new", "vip"],
  "manager": null
}
TSGenerated TypeScript
export interface Customer {
  id: number;
  name: string;
  isActive: boolean;
  address: Address;
  orders: Order[];
  tags: string[];
  manager: null;
}

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

export interface Order {
  orderId: string;
  total: number;
}

The array property orders produced a singular Order type. Note that manager is typed as null because that is all the sample shows; in real code you would usually change it to something like Manager | null.

How JSON values map to TypeScript types

TypeScript types generated for each kind of JSON value
JSON valueGenerated typeNotes
"text"stringDates in JSON are strings too, so ISO timestamps become string.
42, 3.14numberIntegers and decimals share one type.
trueboolean
nullnullWiden it by hand once you know the real type.
{ … }A new named interfaceNamed after the property in PascalCase.
[{ … }]Item[]Named after the singular of the property; the first object defines the shape.
["a", "b"]string[]Mixed values become a union such as (number | string)[].
[]unknown[]An empty array gives no type information.

TypeScript to JSON: placeholder values

When converting types to JSON, the tool uses the interface or type named Root if there is one, otherwise the first declaration, and fills each property with a placeholder:

Placeholder JSON values generated for TypeScript types
TypeScript typeExample JSON value
string"string"
number, bigint0
booleantrue
DateThe current date as an ISO 8601 string
string[], Array<T>An array with one example item
string | nullThe first non-null type in the union
any, unknown, nullnull
Another declared interface or typeA nested example object

Frequently asked questions

Should I use an interface or a type alias?

For describing the shape of JSON data, both work the same way. Interfaces can be extended and merged, which many teams prefer for object shapes; type aliases can also express unions and mapped types. Pick whichever your project already uses for consistency.

Can I paste a JavaScript object instead of JSON?

The input has to be valid JSON, so property names need double quotes and trailing commas aren't allowed. If you have a JavaScript object literal, run JSON.stringify(yourObject, null, 2) in the browser console and paste the result.

What if my JSON is an array at the top level?

The root value must be an object. Paste a single item from the array to generate its interface, then use ItemName[] for the array in your code.

Why aren't any properties marked optional?

A single JSON sample can't show which fields are sometimes missing. Every property found becomes required, and arrays of objects are typed from their first item, so review the output and add ? to fields you know are optional.

Does it support TypeScript features like generics or enums?

TypeScript to JSON is designed for plain data shapes: interfaces, object type aliases, primitives, arrays and references between declared types. Enums, string literal unions like "a" | "b", generics and utility types such as Partial or Record<string, string> aren't resolved and come out as null, so fill those values in by hand.

If the converter reports invalid JSON, find the problem with the JSON validator first.