Tools

Home
JSON FormatterSQL FormatterJS ValidatorMinify CSS
Merge PDFCompress PDFImage to PDF
JPG to PNGPNG to WebPCrop Image

JSON to TypeScript Interface Generator

Paste JSON and instantly generate TypeScript interfaces with proper type mapping, nested objects, and arrays

Your files never leave your browser
Input (JSON)0 chars, 0 lines
Output (TypeScript)0 chars, 0 lines
Ready·

Drop a JSON response into the left panel and get fully typed TypeScript interfaces on the right — nested objects, arrays, nullables, all mapped correctly in one click. And everything runs in your browser. Nothing gets uploaded.

How It Works

Paste JSON
→
Parse & Infer Types
→
TypeScript Interfaces

The converter walks through every key in your JSON, checks the value type, and maps it to the TypeScript equivalent. Strings become string, numbers become number, booleans become boolean. When it hits a nested object, it creates a separate interface named after the key in PascalCase. Arrays get typed based on what’s inside them — and if an array holds mixed types, you’ll get a union like (string | number)[].

Examples

Simple User Profile

Basic flat object from a REST API — the most common case.

INPUT
{ "id": 42, "name": "Sara Chen", "email": "[email protected]", "active": true }
OUTPUT
interface Root { id: number; name: string; email: string; active: boolean; }

Nested API Response with Arrays

A product listing endpoint that returns nested objects and typed arrays. This is where manual typing gets painful fast.

INPUT
{ "product": "Desk Lamp", "price": 49.99, "tags": ["lighting", "office"], "dimensions": { "width": 15, "height": 38, "unit": "cm" } }
OUTPUT
interface Dimensions { width: number; height: number; unit: string; } interface Root { product: string; price: number; tags: string[]; dimensions: Dimensions; }

Config File with Nullable Fields

App config where some values might be null — common in settings files pulled from a database.

INPUT
{ "theme": "dark", "language": "en", "lastLogin": null, "notifications": true }
OUTPUT
interface Root { theme: string; language: string; lastLogin: null; notifications: boolean; }

Who Uses This

👨‍💻 Frontend Developers

Generating types from API responses so fetch calls are fully typed without guesswork.

⚙️ Backend Engineers

Creating shared interface files from JSON payloads to keep the API contract in sync with the client.

🎓 Students

Learning how TypeScript types map to JSON structures — seeing the output teaches more than reading docs.

🧪 QA Engineers

Building typed test fixtures from real API snapshots to catch schema regressions early.

Common Mistakes

Pasting invalid JSON

Trailing commas, single quotes, or unquoted keys will break the parser. Run your JSON through a validator first, or check the error message — it usually points right at the problem line.

Using a sample with all null values

If a field is null in your sample, the tool can only type it as null — it has no way to guess the real type. Use a response where the field actually has data, then mark properties optional if needed.

Assuming the generated types cover every edge case

The tool types what it sees. If your API sometimes returns a string and sometimes a number for the same field, but your sample only has the string version, the interface won’t include number. Feed it a representative sample with all possible shapes.

Technical Details

Frequently Asked Questions

What’s the difference between a TypeScript interface and a type alias?

An interface uses interface Foo { ... } and can be extended or merged across files. A type alias uses type Foo = { ... } and is more flexible — it handles unions, intersections, and mapped types. For plain object shapes they’re interchangeable, so pick whichever your team prefers.

How are nested objects handled?

Each nested object gets its own named interface. The name comes from the property key converted to PascalCase. So a key called "shipping_address" produces an interface named ShippingAddress. The parent interface then references it by that name instead of inlining the shape.

Can I convert JSON with arrays of different types?

Yes. If an array contains strings and numbers, the output will be (string | number)[]. Arrays of objects produce a typed array referencing a generated interface. Empty arrays become any[] since there’s nothing to infer from.

Is my JSON data safe when using this tool?

Completely. The conversion runs in JavaScript right inside your browser tab. Nothing gets sent to a server. You can disconnect from the internet and it still works — go ahead and try it.

When should I mark all properties as optional?

Turn on “Optional” when your API doesn’t always return every field — partial responses, PATCH endpoints, that kind of thing. It adds ? to each property so TypeScript knows the value might be undefined. For endpoints that always return the full object, leave it off. Tighter types catch more bugs.

Share: