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
// Paste JSON on the left // to generate TypeScript interfaces
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
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
extends&)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.
Yes. Copy the raw JSON from your browser's network tab, Postman, or any API testing tool, paste it into the input panel, and the converter generates every interface the response needs, including nested ones.
Arrays of primitives become string[]/number[]/boolean[]. Arrays of objects generate a named interface plus []. Mixed-type arrays become a union like (string | number)[], and empty arrays become unknown[] since there's no sample element to type.
Both describe the same object shape and are largely interchangeable. Interfaces support extends and declaration merging, which is the convention for public APIs and libraries. Type aliases are more flexible for unions and intersections.
In a single object, a field with a null value is typed as null, and you'll usually want to widen it to string | null or similar by hand. In an array, the tool merges every item: if name is null in one and "Ann" in another, you get name: string | null; without editing anything.
Nested interfaces are named after their key in PascalCase, without singularizing it. A users array of objects becomes users: Users[] with an interface Users. Rename it to User in your code if you prefer singular names. When two different shapes share a key name, the second one gets a number, like Users2.
No — the tool runs entirely in your browser, so it can handle large API responses or config files without a server round trip. Very large inputs may just take a moment longer to render the syntax-highlighted output.
Further reading
Related Tools
- CSV to JSON Converter & JSON to CSV Online Developer Paste or upload a CSV (comma, semicolon, tab or pipe) and get clean JSON. Also converts JSON to CSV that Excel opens without garbled characters.
- JSON Mock Data Generator — Fake JSON for Testing Developer Generate realistic mock JSON data for testing and prototyping — users, products, orders, and custom schemas. Runs entirely in your browser.
- YAML to JSON Converter & JSON to YAML Online Developer Paste YAML from docker-compose, Kubernetes or GitHub Actions and get JSON instantly, with anchors expanded and multi-document files (---) as an array.
- ASCII Table Generator: Plain-Text & Markdown Tables Developer Turn CSV or typed data into a plain-text table: MySQL, Unicode box, rounded, double-line, Markdown, RST or minimal style. Copy it or download as .txt.
- HTML to Markdown Converter with GFM Tables & Live Preview Developer Paste HTML and get clean Markdown instantly: GFM tables and strikethrough, ATX or Setext headings, live preview and .md download. Runs in your browser.