JSONGenerator
GeneratorSchemaConvertersExamplesDocs

JSONGenerator

Free online tools for generating random JSON data and JSON Schemas.

Quick Links

  • JSON Generator
  • JSON Schema Converter
  • Examples
  • Docs
  • Blog
  • About
  • Contact
  • Privacy Policy

Converters

  • JSON to YAML
  • YAML to JSON
  • XML to JSON
  • JSON to XML
  • JSON to TOML
  • TOML to JSON
  • JSON to CSV
  • CSV to JSON
  • JSON to Excel
  • Excel to JSON
  • JSON to HTML table
  • JSON to TypeScript
  • JSON to C#
  • JSON to Go
  • JSON to Java
  • JSON to SQL

Support

Having issues? Contact us.

© 2026 JSON Generator. All rights reserved.

JSON to TypeScript Converter

Paste JSON and get TypeScript interfaces for it as you type.

JSON Input

Paste JSON, upload a .json file or drop one here.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
{
  "id": 1042,
  "name": "Ada Lovelace",
  "email": "ada@example.com",
  "active": true,
  "createdAt": "2024-03-15T09:30:00Z",
  "manager": null,
  "address": {
    "street": "12 Analytical Way",
    "city": "London",
    "geo": { "lat": 51.5074, "lng": -0.1278 }
  },
  "roles": ["admin", "editor"],
  "orders": [
    { "id": "A-100", "total": 59.9, "items": [{ "sku": "KB-01", "qty": 1 }] },
    { "id": "A-101", "total": 12, "coupon": "SPRING", "items": [{ "sku": "MS-02", "qty": 2 }] }
  ],
  "lastLogin": [1710495000, "never"]
}

TypeScript Output

Updates as you type. Copy it or download types.ts.

1

Converting…

Convert JSON to TypeScript online

This free JSON to TypeScript converter reads a JSON document and writes the TypeScript interfaces that describe it. Paste an API response, a config file or a fixture, and you get a root interface plus a named interface for every nested object, with arrays typed, optional properties marked and differing value types combined into unions. It saves you from typing out types for a large response by hand, and from the typos that come with it.

Everything runs in your browser. Your JSON is not uploaded, so you can paste a real response without worrying about what it contains. There is nothing to install and no account to create. The output is plain interface or type declarations with no runtime code, ready to drop into a types.ts file.

How to convert JSON to TypeScript interfaces

  1. Paste your JSON into the JSON Input editor, or click the upload button to open a .json file. You can also drag a file onto the editor.
  2. The TypeScript Output updates as you type. If the JSON is invalid, the status bar shows the parser's error so you can fix it.
  3. Set the Root type name to something meaningful such as User or ApiResponse. Spaces and punctuation are cleaned up so the name is always a valid identifier.
  4. Choose whether to declare as an interface or a type alias, and tick readonly properties if the data should not be modified.
  5. Click Copy to put the code on your clipboard, or Download to save it as types.ts.

JSON to TypeScript interface example

The root object becomes User, using the name typed in the options. The nested address object becomes Address, and the objects inside the orders array become one Order interface. Because only the second order has a coupon, coupon is optional.

JSON input
{
  "id": 1,
  "name": "Ada",
  "address": { "city": "London" },
  "orders": [
    { "id": "A-1", "total": 9.5 },
    { "id": "A-2", "total": 12, "coupon": "SPRING" }
  ]
}
TypeScript output
export interface User {
    id:      number;
    name:    string;
    address: Address;
    orders:  Order[];
}

export interface Address {
    city: string;
}

export interface Order {
    id:      string;
    total:   number;
    coupon?: string;
}

How types are inferred from JSON

The converter looks at the values in your sample and picks the TypeScript type that fits every one it sees. It is only as informed as the sample, which is why a few cases need your attention.

JSON values and the TypeScript types they produce
JSON valueTypeScript typeNotes
stringstringISO 8601 timestamps stay string, as JSON has no date type.
numbernumberIntegers and decimals are both number.
true / falseboolean
nullnullBecomes a union such as string | null when other items hold a value.
objectA named interfaceNested objects each get their own interface.
arrayT[]Mixed contents become Array<number | string>.
empty arrayunknown[]There are no items to learn the type from.

One sample cannot show optional properties

A single object has exactly one value for each key, so every property looks required. To get coupon?: string, give the converter several examples in an array. A property that is missing from some items is marked optional, and a property whose type differs between items becomes a union. If you start from one response, paste two or three different ones inside [ ].

A top-level array of objects produces one interface for the items, not an array type, so [{ ... }, { ... }] gives you Root describing a single element. Use Root[] where you need the list.

How nested interfaces are named

A nested object is named after the property that holds it, in PascalCase: address becomes Address. For arrays the name is singular, so orders becomes Order. When two different shapes would end up with the same name, the second gets a prefix from its parent, such as AItem and BItem.

Objects with exactly the same shape are merged into one interface. If billing and shipping both contain just a street, they will share a single type, and the name it gets may not be the one you would choose. Rename it in your editor; that is a quick find-and-replace.

null, unions and objects used as dictionaries

A property that is null in your only sample becomes null, which is rarely what you mean. Replace it with the real type, for example Manager | null, or add a second sample where the value is present.

If an object uses IDs or names as its keys, such as { "u1": {...}, "u2": {...} }, the converter writes one property per key, because it cannot know the keys are arbitrary. For a real dictionary, replace that interface with Record<string, User> by hand.

Interface or type alias?

Both describe the same object shapes. Interfaces can be extended and merged with extends, while type aliases can also name unions and tuples. Pick whichever your codebase already uses. The readonly properties option adds readonly to every property; it does not change the types of arrays, which stay mutable.

Using the generated types in your code

Save the output as types.ts and import the interfaces where you handle the data. With fetch you assert the type of the parsed body, and with axios you pass it as a generic.

fetch and axios
import type { User } from "./types";

// fetch: assert the type of the parsed body
const res = await fetch("/api/users/1");
const user = (await res.json()) as User;

// axios: pass the type as a generic
const { data } = await axios.get<User>("/api/users/1");

Keep in mind that both are only assertions: TypeScript does not check that the response really has that shape. When the data comes from an API you do not control, validate it at runtime with a library such as Zod. Write the schema using the generated interface as your reference, and annotate it with z.ZodType<User> so the compiler tells you if the two ever disagree.

Zod schema checked against the interface
import { z } from "zod";
import type { User } from "./types";

// The annotation fails to compile if the schema drifts from the interface
const UserSchema: z.ZodType<User> = z.object({
  id: z.number(),
  name: z.string(),
  address: z.object({ city: z.string() }),
  orders: z.array(
    z.object({ id: z.string(), total: z.number(), coupon: z.string().optional() })
  ),
});

const user = UserSchema.parse(await res.json()); // throws if the data does not match

Why convert JSON to TypeScript?

  • Typing API responses: Paste a response from your backend or a third-party API and get types for it in seconds.
  • Mock data and test fixtures: Describe fixture files so editors flag a field that has the wrong name or type.
  • Config and settings files: Give a JSON config a type so a missing key or typo is a compile error.
  • Migrating JavaScript: Start from real data when adding types to an untyped codebase.

If you only have a description of the data rather than a sample, generate a schema first with the JSON Schema Generator, or create realistic sample data with the JSON Generator and convert that. Working in another language? Try the JSON to C# class converter, the JSON to Go struct converter or the JSON to Java class converter. Comparing formats for typed contracts between services? Read Protobuf vs JSON.

Frequently Asked Questions

How do I convert JSON to a TypeScript interface?

Paste your JSON into the JSON Input editor, or upload a .json file. The TypeScript interfaces appear in the output editor as you type. Copy them, or click Download to save types.ts.

How do I make a property optional?

A single object cannot show which fields are optional, because it only has one value for each. Wrap several examples in an array and the converter marks any property that is missing from some of the items with a question mark, such as coupon?: string.

Does the converter create a separate interface for each nested object?

Yes. Every nested object gets its own named interface, named after its property: an address object becomes Address, and items in an orders array become Order. Objects with identical shapes share one interface.

Should I use an interface or a type alias?

For plain object shapes they behave almost the same. Interfaces can be extended and merged, while type aliases can also describe unions and tuples. Pick one in the Declare as menu and the whole output follows it.

Why does a null value become the type null?

A sample that contains only null tells the converter nothing about the real type, so it writes null. If the same property is a string in another array item, the result is a union such as null | string. Replace a lone null with the type you expect, for example Manager | null.

Does the generated TypeScript check my data at runtime?

No. TypeScript types are erased when your code is compiled, so they describe data but do not validate it. To check API responses at runtime, write a schema with a library such as Zod, using the generated interface as your guide.

Is my JSON uploaded to a server?

No. The types are generated in your browser, so your JSON never leaves your device. That makes it safe to use with real API responses that contain private data.

Related converters

  • JSON to C# Class ConverterGenerate C# classes with properties for System.Text.Json or Newtonsoft.Json from JSON.
  • JSON to Go Struct ConverterGenerate Go structs with json tags from a JSON sample.
  • JSON to Java Class ConverterGenerate Java POJO classes with getters and setters from JSON.
  • JSON to SQL ConverterGenerate a CREATE TABLE statement and INSERT rows from a JSON array.
  • JSON to YAML ConverterConvert JSON to clean, readable YAML for config files, Kubernetes and CI pipelines.
  • YAML to JSON ConverterConvert YAML, including anchors and multi-document files, to formatted JSON.

See all JSON converters