JSON to TypeScript Converter
Convert JSON to TypeScript interfaces or types online for free. Paste or upload JSON, create types for nested objects, arrays and optional fields, then copy or download ready-to-use TypeScript code. Your data stays in your browser.
export type Root = RootItem[];
export interface RootItem {
id: number;
name: string;
email?: string;
}
What Is a JSON to TypeScript Converter?
A JSON to TypeScript converter creates interfaces and type aliases from sample JSON. Instead of defining every field by hand, you can quickly create useful type information for an API response, configuration file or example record.
This converter handles nested objects, arrays, missing fields and mixed values. The generated types describe the examples you provide. They do not automatically check incoming JSON when your app runs or guarantee that future responses have exactly the same fields.
How to Convert JSON to TypeScript Online
Paste or upload JSON
Start with an object, array, or .json file from your device.
Choose output options
Select Interface or Type alias, choose the main type name, and decide whether to export types or make fields readonly.
Copy or download code
Check the TypeScript preview, then copy it or download the complete types.ts file.
JSON to TypeScript Interface Example
In this example the JSON is a top-level array of two objects. Both haveid and name, but only the first has email. The generated RootItem interface therefore usesemail?: string, and the root type is RootItem[].
[
{
"id": 1,
"name": "Ada",
"email": "ada@example.com"
},
{
"id": 2,
"name": "Ben"
}
]export type Root = RootItem[];
export interface RootItem {
id: number;
name: string;
email?: string;
}
Generate TypeScript Types from Nested JSON
Nested JSON objects become named TypeScript types, and the fields that contain them refer to those types. For an array of users, the item type is usually named User. The generator examines every object in an array before deciding which fields belong in that type.
Example: special JSON keys and duplicate type names
JSON permits property names such as user-profile and first-name, which must be quoted in TypeScript. Two properties can also suggest the same type name: user and usersboth suggest User. The converter gives the second type a numbered name, such as User2, so the two types stay separate.
{
"user-profile": {
"first-name": "Ada"
},
"user": {
"id": 1
},
"users": [
{
"id": 2,
"name": "Ben"
}
]
}export interface Root {
"user-profile": UserProfile;
user: User;
users: User2[];
}
export interface UserProfile {
"first-name": string;
}
export interface User {
id: number;
}
export interface User2 {
id: number;
name: string;
}
You can also set the Main type name in Conversion options. If the name contains spaces or starts with a number, it is adjusted to a valid TypeScript name and the tool displays a notice.
Optional vs Nullable TypeScript Properties
Optional and nullable describe different things. A property is optional when it is missing from one or more example objects, which produces a question mark such as email?: string. A field is nullable when an example explicitly contains null, which may produce nickname: string | null.
Example: an optional email and a nullable nickname
Both people have an id and nickname, but only one has an email. The second nickname is text while the first is null. The generated types reflect both differences.
[
{
"id": 1,
"nickname": null,
"email": "ada@example.com"
},
{
"id": 2,
"nickname": "Bee"
}
]export type ContactList = ContactListItem[];
export interface ContactListItem {
id: number;
nickname: string | null;
email?: string;
}
| In the JSON examples | TypeScript result |
|---|---|
| Field appears in every object | Required property, without ? |
| Field is missing from some objects | Optional property with ? |
Field contains text and null | string | null |
Field is both sometimes missing and sometimes null | Optional property whose type includes null |
| Only one object is provided | Present fields are shown as required; review them manually |
A field can be optional and nullable at the same time. TypeScript may allow undefined when your code reads an optional property. JSON itself has no undefined value, so the converter only adds nullwhen it appears in your sample. With a single example, it cannot know which fields could be absent from future API responses.
Arrays, Union Types and Empty Values
JSON arrays become TypeScript arrays. A list of numbers becomes number[]; a list containing numbers and text becomes (string | number)[]. The converter combines types from all observed elements, including nested arrays and arrays of objects, rather than looking at only the first value.
[
{
"id": 1,
"nickname": null,
"tags": [
"api",
"json"
],
"score": 8
},
{
"id": 2,
"nickname": "Bee",
"tags": [],
"score": 9.5,
"enabled": true
}
]export type UserList = UserListItem[];
export interface UserListItem {
id: number;
nickname: string | null;
tags: string[];
score: number;
enabled?: boolean;
}
| JSON example | Generated TypeScript |
|---|---|
[1,2,3] | number[] |
["a","b"] | string[] |
[1,"a"] | (string | number)[] |
[] | unknown[] |
{} | Record<string, unknown> |
null only | null — other types cannot be guessed |
If one example contains an empty array but another contains elements at the same field in the examples, the populated array provides the item type. Otherwise an empty array becomes unknown[]. An empty object becomes Record<string, unknown> because there are no fields to infer. These are cautious defaults, not guesses about future data.
TypeScript Interface vs Type Alias
Choose Interface for an object type such as interface User, or Type alias for type User = .... Both styles can describe the same object fields; the option changes how the type is written.
Example: the same JSON in both output modes
The first output uses Interface mode with export keywords. The second uses Type alias mode without export keywords and with readonly fields. Both examples come from the same JSON input.
export interface User {
id: number;
name: string;
roles: string[];
}
type User = {
readonly id: number;
readonly name: string;
readonly roles: string[];
};
| Input shape | Interface mode | Type alias mode |
|---|---|---|
| Named object | interface User | type User = ... |
| Top-level array | Uses type Root = ...[] | Uses type Root = ...[] |
Top-level string, number, boolean or null | Uses a type alias | Uses a type alias |
| Readonly setting | Prevents object fields from being reassigned; array items can still be changed | |
A top-level array or a single value such as a string, number, boolean, or null uses a type alias even when Interface is selected. An interface describes an object shape. The Export types setting controls whether generated types can be imported from the downloaded TypeScript file.
JSON to TypeScript vs JSON Schema Generator
| Tool | Output | Best for |
|---|---|---|
| JSON to TypeScript | interface / type in a .ts file | Type information and editor suggestions while writing code |
| JSON Schema Generator | .json Schema | Documenting structures or validating with a compatible Schema validator |
| JSON Validator | Syntax feedback | Finding invalid JSON quotes, commas, and brackets |
Need a reusable description of your JSON structure? Use the JSON Schema Generator. To check syntax first, try the JSON Validator. TypeScript types do not automatically check incoming data when your application runs.
Common JSON to TypeScript Problems
| What you see | What to do |
|---|---|
| Every field is required | One object cannot reveal optional properties. Add more example objects with missing fields. |
A property includes | null | At least one example contains an explicit null. This is different from a missing field. |
An empty array becomes unknown[] | Include representative elements to reveal the array item types. |
| Two generated types would have the same name | The tool adds a number, such as User2, to keep both types separate. |
| A JSON key includes spaces or hyphens | The tool quotes property names that need quotation marks in TypeScript. |
| Very large JSON integers | TypeScript uses number; very large integers may lose precision when JavaScript uses them. |
| The generated type differs from an API response | Add more representative examples, then review optional fields and union types. |
| JSON cannot be parsed | Check brackets, commas and quotes, or use the JSON Validator. |
| The file is very large or deeply nested | Try a smaller example that includes the fields and values you need to represent. |
Long results are shortened in the preview to keep the page easy to use. Copy or download types.ts to get the complete generated code.
Frequently asked questions
How do I convert JSON to TypeScript online?
Paste a JSON object or array, or choose a .json file. Click Convert to TypeScript, review the generated types, then copy or download types.ts.
Can I generate a TypeScript interface from JSON?
Yes. Interface is the default output style for named objects. If your JSON is an array or a single value such as a string, number, boolean, or null, the converter uses a type alias because an interface can only describe an object shape.
Can I generate TypeScript type aliases instead?
Yes. Choose Type alias in Conversion options. Named object types will use type aliases instead of interfaces.
Does it support nested JSON objects?
Yes. Nested objects become their own named types, which are then used by the fields that contain them. If two objects would get the same name, the converter adds a number, such as User2, so both can appear in the result.
Can it convert JSON arrays to TypeScript arrays?
Yes. An array of objects becomes a named item type, such as User[]. If an array contains different kinds of values, the result uses a union, such as (string | number)[]. An empty array becomes unknown[] because there are no items to inspect.
How are optional TypeScript properties detected?
When you provide an array of example objects, a property becomes optional if it is missing from at least one object. With only one object, the converter cannot tell which fields might be missing from future data.
What is the difference between optional and nullable?
A property that is missing from some objects gets a question mark, such as email?: string. A property that contains null gets a type such as string | null. A property can be both optional and nullable.
What happens with empty JSON objects or arrays?
An empty array becomes unknown[] because there are no items to identify its type. An empty object becomes Record<string, unknown>, meaning it can contain any property name but the value types are not known yet.
Can I change the generated type name?
Yes. Enter a name under Main type name in Conversion options. If it contains characters that TypeScript does not allow, the converter adjusts it and shows a notice.
Can I export generated types or make fields readonly?
Yes. Generated types include the export keyword by default, so you can import them from another file. You can turn this off or make object fields readonly. Readonly prevents replacing a field's value, but it does not prevent changes to items inside an array.
Is my JSON uploaded to a server?
No. Your JSON is read and converted in your browser. Neither your input nor the generated TypeScript code is sent to our servers.
Can I download a TypeScript file?
Yes. Copy the result or download it as types.ts. Long results are shortened in the preview, but copying or downloading gives you the complete TypeScript code.
Does the generated TypeScript check incoming JSON data?
No. TypeScript types help your editor check code while you are writing it, but they do not automatically check incoming JSON when your app runs. If you need to check real data, generate a JSON Schema and use it with a compatible validator.
Can I use the generated types for any future API response?
The generated types reflect only the examples you provide. If an API can return additional fields or different value types, add more examples and review the result before using it.