KickSolve • Free • Private

JSON to TypeScript Types

Paste JSON and get TypeScript interfaces straight away. Nested objects get their own interface, arrays are merged into one type, and fields missing from some items become optional. Nothing is uploaded.

Nested interfacesOptional fieldsNever uploaded

How to use JSON to TypeScript Converter on KickSolve

Three quick steps, no account needed.

Paste your JSONPaste a sample of the JSON you work with, such as an API response.
Pick the optionsSet the root name, choose interface or type, and decide whether to add export.
Copy or download the typesCopy the TypeScript or download it as a .ts file and drop it into your project.

Why choose KickSolve

Built for speed, privacy and clean results.

Private by designEverything runs in your browser. What you paste or open is never uploaded or stored.
Instant, no signupFree to use with no account, no limits on how often you use it, and no software to install.
Merges array itemsItems in an array are combined into a single type, and fields missing from some items become optional.
Readable namesInterfaces are named from your keys in PascalCase, with array names singularised, such as Users becoming User.

What you can do with JSON to TypeScript Converter

Everything this tool is good for.

Typing API responsesCreate types for a REST response in seconds instead of writing them by hand.
Migrating JavaScript to TypeScriptGenerate a first draft of types for existing data.
Config and fixture filesType the shape of JSON configs and test fixtures.
Front-end stateModel data you receive from a back end.
DocumentationShow the shape of a payload as a type.
Quick prototypesGet typed access to sample data before the real API exists.
Learning TypeScriptSee how objects, arrays and unions are described.
Checking data shapeSpot fields that are sometimes missing or change type.

About JSON to TypeScript Converter on KickSolve

What it does, how it works and how to get the best results.

How types are inferred

The tool reads your JSON and describes each value: strings, numbers, booleans and null, nested objects as their own interfaces, and arrays as lists of the merged item type. It is inferred from the sample, so the more representative your sample, the better the types.

Optional fields and unions

When array items have different keys, a key missing from some items is marked optional with a question mark. When the same key holds different types, the type becomes a union such as string | number. A null value is typed as null, so add it to a union yourself if the real field can also hold a value.

Interface or type

Interfaces are the usual choice for object shapes and can be extended. Type aliases work the same for these shapes and are handy if your project prefers them. The Export setting adds the export keyword to every declaration.

Limits to keep in mind

All numbers become number, dates arrive as strings, and an empty array becomes unknown[] because there is nothing to infer from. Review the output and tighten the types by hand where you know more than the sample shows.

Related tools

Format and validate your JSON first with the JSON Formatter, explore it with the JSONPath Tester, or turn it into a table with JSON to CSV.

Worked example: JSON to TypeScript

Nested objects and an array with a missing field.

Input:
{"id": 1, "name": "Ana", "address": {"city": "Lahore"},
 "orders": [{"sku": "A1", "qty": 2}, {"sku": "B2"}]}

Output:
export interface Order {
  sku: string;
  qty?: number;
}

export interface Address {
  city: string;
}

export interface Root {
  id: number;
  name: string;
  address: Address;
  orders: Order[];
}

The second order has no qty, so qty is optional. Each nested object became its own interface.

How JSON maps to TypeScript

The type chosen for each kind of value.

JSON valueTypeScript type
"text"string
12 or 1.5number
trueboolean
nullnull
ObjectIts own interface, or Record<string, unknown> if empty
Array of objectsA merged interface array, with optional fields where items differ
Mixed types for one keyA union, such as string | number
Empty arrayunknown[]

Frequently asked questions

Quick answers.

How do I convert JSON to TypeScript?

Paste your JSON, set the root name and options, and copy the generated interfaces. They update as you type.

Should I use interface or type?

Either works for these shapes. Interfaces are the common choice for objects, and type aliases are fine if your project prefers them. Use the Declaration setting to switch.

How are optional fields decided?

A field that is missing from at least one item in an array is marked optional with a question mark.

What happens when a field has different types?

The type becomes a union of the types that were seen, such as string | number.

Why is my array typed as unknown[]?

An empty array gives the tool nothing to infer from. Replace unknown with the real item type.

Are dates and integers detected?

No. Dates arrive in JSON as strings and every number is typed as number. Adjust these by hand if you need more precise types.

Can I generate types from several API responses?

Put several sample items into one array so the tool can merge them and find the optional fields.

Is my JSON uploaded?

No. The types are generated in your browser and nothing is sent to a server.

More free tools from KickSolve

Related free tools. Each one runs in your browser too.