JSON to TypeScript: Generate Interfaces or Types Online

JSON to TypeScript: Generate Interfaces or Types Online

Paste JSON and get TypeScript interfaces or types, with nested objects and optional fields inferred from every array item. Also repairs broken JSON.

Updated November 2026

Reviewed by Rafael Duarte

Root Interface Name
Output
1
TypeScript Interface

// Paste JSON on the left // to generate TypeScript interfaces

Shift + Enter to Copy

How to convert JSON to TypeScript

From raw JSON to production-ready interfaces in three steps

1. Paste your JSON

An API response, a config file, a database record: any JSON object or array works. Want to see it first? Click Sample to load an example payload.

2. Name the root interface

Defaults to RootObject — rename it to something that matches your domain, like User or Product.

3. Copy the result

Click Copy, or press Shift+Enter while the cursor is outside the input fields, then paste straight into your .ts/.tsx files.

What this JSON to TypeScript generator does

Handles the full range of JSON shapes you'll actually paste in

Nested objects

Every inner object gets its own named interface, ordered so dependencies appear before they're used.

Typed arrays

Primitive arrays become string[]/number[]; arrays of objects generate an interface plus [].

Interface / type toggle

Switch between interface and type output to match your project's convention.

Optional fields and unions from every array item

Some converters only look at the first element of an array. This one merges all items: a key missing from some objects becomes optional (?), and a key holding different types becomes a union such as string | number.

Null fields

A lone null is typed as null. When the same key is null in one array item and text in another, the output is already string | null.

Fix broken JSON

Trailing commas, single quotes or missing brackets? The error shows the parser message (with line and column when your browser reports them) and a Fix button that tries to repair the JSON in place.

How each JSON type maps to TypeScript

JSON
TypeScript
"text"
string
42
number
true
boolean
["a", "b"]
string[]
{"profile": {...}}
profile: Profile (+ separate Profile interface)
[{"a":1},{"a":1,"b":"x"}]
a: number; b?: string;
[{"id":1,"name":null},{"id":2,"name":"Ann"}]
id: number; name: string | null;

When you'll reach for this tool

The scenarios developers hit most often

Type REST API responses

Paste the JSON your backend returns and get interfaces ready to plug into fetch or axios. Still deciding whether types pay off? Read Is TypeScript worth it for small projects?

Type configuration files

Turn a config.json into an interface so your editor autocompletes every key.

Skip the boilerplate

Stop hand-writing interfaces for deeply nested payloads and let the generator do it in one paste.

Integrate third-party APIs

Paste a sample response to understand the shape and generate a starting set of types.

Common mistakes

Expecting automatic optional fields

? is only inferred when items of the same array differ. In a single object every field is required and a null value is typed as null — widen those types by hand where a field can be missing.

Treating null as the final type

This only happens when you paste a single sample. If the key is null in one object, widen it by hand to string | null (or whatever the field can actually hold). Paste an array with several items instead and the union comes out on its own.

Empty arrays without context

These come out as unknown[] — the element type can't be inferred without at least one sample item.

Why use this converter

It walks nested structures recursively, generating one interface per level and ordering them so dependencies are declared before they're referenced — no manual sorting required.

Output is compatible with TypeScript 3.0+ and works the same in React, Next.js, Vue, Angular, or plain Node.js — nothing framework-specific about the generated types.

interface vs. type

Both are available via the toggle in the tool

interface
type
Supports extends
yes
via intersection (&)
Declaration merging
yes
no
Best for
public APIs, libraries
complex unions and intersections

Frequently asked questions

Paste the JSON and the generator handles nested objects recursively, giving each one its own named interface, ordered so dependencies appear before they're used. There's no depth limit — deeply nested API responses work the same as flat ones.

Further reading

Related Tools