JSON to TypeScript Converter

Paste any JSON and get clean TypeScript interfaces or types in one click. Nested objects, arrays and optional fields are handled for you. Free, no signup, and it runs in your browser.

Invalid
JSON Input
TypeScript Output
Share on WhatsApp Back to Home Page

What is a JSON to TypeScript Converter?

A JSON to TypeScript converter reads a sample of JSON data and writes the matching TypeScript types for it. Instead of typing an interface by hand for every API response, you paste the response and get ready-to-use code. Strings become string, numbers become number, true or false becomes boolean, lists become arrays and objects become interfaces.

This saves time when you work with REST APIs, config files or mock data, and it helps your editor catch mistakes such as a misspelled property name before you run the code.

How to Use the JSON to TypeScript Converter

  1. Paste your JSON into the input box, or upload a .json file.
  2. Set the root name, for example User or ApiResponse.
  3. Choose interface or type, and options such as export, readonly and optional properties.
  4. Copy the TypeScript output or download it as a .ts file. If the JSON has an error, fix the line and column shown.

JSON to TypeScript Example

JSON input:

{
  "id": 101,
  "name": "Rahul",
  "isActive": true,
  "email": null,
  "tags": ["dev", "admin"],
  "address": {
    "city": "Delhi",
    "pin": "110001"
  }
}

TypeScript output:

export interface Root {
  id: number;
  name: string;
  isActive: boolean;
  email: null;
  tags: string[];
  address: Address;
}






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

Array of Objects and Optional Properties

When an array holds several objects, the tool merges them into a single interface. A key that is missing from some objects becomes optional.

JSON input:

[
  { "id": 1, "name": "Asha" },
  { "id": 2, "email": "[email protected]" }
]

TypeScript output:

export type Root = Item[];

export interface Item {
  id: number;
  name?: string;
  email?: string;
}

Interface vs Type: Which One to Use?

Featureinterfacetype
Describes object shapesYesYes
Extend another shapeextendsIntersection with &
Declaration merging (same name twice)YesNo
Union types (string | number)NoYes
Primitives and tuplesNoYes
Typical use for API dataVery commonEqually fine

For JSON data both give the same result in practice. Follow the style already used in your project.

How JSON Types Map to TypeScript

JSON valueTypeScript type
"text"string
42 or 3.14number
true / falseboolean
nullnull
[1, 2, 3]number[]
[1, "a"](number | string)[]
[] (empty)unknown[]
{ ... }Named interface or type

TypeScript Types vs Zod Schema

TypeScript types are removed when your code is compiled, so they cannot check data that arrives while the app is running. If you need to check an API response at runtime, a Zod schema does that. This tool can also generate a Zod schema from your JSON, so you get both from one paste.

import { z } from "zod";

export const AddressSchema = z.object({
  city: z.string(),
  pin: z.string(),
});

export const RootSchema = z.object({
  id: z.number(),
  name: z.string(),
  address: AddressSchema,
});

export type Root = z.infer<typeof RootSchema>;

Limitations of Generating Types from JSON

  • Only one sample is seen: The types match the JSON you paste. Fields or values that the API sometimes returns but are not in your sample will be missing.
  • Empty arrays: They become unknown[] because there is nothing to inspect.
  • Null-only fields: A value that is null in your sample is typed as null, although the real type may be string | null.
  • Dates: JSON has no date type. Dates arrive as strings, so they are typed as string unless you convert them yourself.
  • Large numbers: JSON parsed in JavaScript loses precision above 9007199254740991. Keep long IDs as strings in the API.
  • Duplicate keys: If a key appears twice in one object, the last value wins before the types are generated.

Always review the generated code and compare it with your API documentation before you rely on it.

Common JSON Mistakes

  • Trailing comma: A comma after the last item is not valid JSON.
  • Single quotes: JSON needs double quotes for keys and strings.
  • Unquoted keys: {name: "A"} is a JavaScript object, not JSON.
  • Comments: // and /* */ are not allowed in JSON.
  • NaN, Infinity or undefined: These values do not exist in JSON.

Frequently Asked Questions

How do I convert JSON to TypeScript?

Paste your JSON into the input box and the tool generates TypeScript right away. Objects become interfaces, arrays become typed lists, and nested objects get their own named interfaces. Copy the result or download it as a .ts file.

Should I use interface or type in TypeScript?

For plain object shapes like API responses, both work. Interfaces can be extended and merged, and type aliases can also describe unions and other non-object types. This tool lets you generate either one, so pick the style your project uses.

How does the tool decide which properties are optional?

When an array contains several objects, the tool merges them into one interface. A key that is missing from some of the objects is marked optional with a question mark, for example email?: string.

How are null values handled?

A null value is typed as null. If the same key holds a string in one object and null in another, the tool creates a union such as string | null. A key that only ever appears as null in your sample gives type null, so check it against your API documentation.

Why do I get unknown[] for an empty array?

An empty array gives the tool no items to inspect, so it cannot know the element type and uses unknown[]. Add at least one sample item to the array in your JSON to get a proper type.

Are the generated types always correct for my API?

The tool only sees the sample you paste. If the API can return extra fields, different types or null values that are not in your sample, the generated types will not include them. Use a response that shows as many cases as possible and review the output.

What is the difference between a TypeScript type and a Zod schema?

TypeScript types exist only while you write and compile code and are removed at runtime. A Zod schema is real code that checks data while the app runs, for example an API response, and can also give you the TypeScript type from the same definition.

Is this JSON to TypeScript converter free and private?

Yes. The tool is free, needs no signup and runs in your browser using JavaScript. Your JSON is not sent to our server. Still, avoid pasting real passwords, API keys or production data into any online tool.