JSON to TypeScript Interface Generator
Paste any JSON and generate TypeScript interfaces instantly — nested objects, arrays, optional fields, and null types all handled automatically.
JSON Input
TypeScript Interfaces
How to Generate TypeScript Interfaces from JSON
Paste your JSON
Copy a JSON response, config file, or any JSON object and paste it into the input panel. The JSON can be minified or pretty-printed.
Set a root name (optional)
Enter a name for the top-level interface. Defaults to Root. Use something meaningful like User, ApiResponse, or Config.
Generate and copy
Click Generate Interfaces. Copy the output or download it as a .ts file ready to drop into your TypeScript project.
What Are TypeScript Interfaces?
A TypeScript interface defines the shape of an object — which properties it has, what type each property is, and whether any properties are optional. TypeScript uses interfaces to enforce structure at compile time, catching mismatched types and missing fields before your code runs.
When you fetch data from an API or read from a database, the result is typically untyped. Defining an interface for that data lets you use IDE autocomplete, refactor safely, and get immediate feedback if the API response shape changes.
Example
interface User {
id: number;
name: string;
email: string;
isActive: boolean;
address: Address;
}
interface Address {
street: string;
city: string;
zip: string;
}How the Generator Works
Type inference
Each JSON value is inspected at runtime: strings become string, numbers become number, booleans become boolean, and nulls become null.
Nested objects
When a value is an object, the generator recurses and creates a separate named interface for it. The name is derived from the key using PascalCase conversion — an address field becomes an Address interface.
Arrays of objects
When an array contains objects, all elements are merged into a single interface. Any key that appears in only some elements is marked optional (key?). This handles APIs that omit nullable fields rather than returning them as null.
Mixed-type arrays
Arrays containing multiple value types produce a union array type — for example, an array with both strings and numbers becomes (string | number)[].
Name deduplication
If two different nested objects would produce interfaces with the same name, a numeric suffix is appended automatically — Item, Item2, Item3 — to avoid conflicts.
Use Cases
API Response Typing
Paste the JSON response from an API endpoint to generate a typed interface. Use it to type your fetch() or axios calls and get IDE autocomplete on the response data.
Database Document Shapes
Convert MongoDB document samples or DynamoDB item snapshots into TypeScript interfaces for your data access layer — no manual transcription needed.
Config File Schemas
Turn a JSON config file into an interface so your config-loading code is fully typed. Any field missing from the real config will surface as a compile-time error.
Onboarding to a Legacy Codebase
Found an undocumented JSON payload in an old codebase? Paste an example response and generate the interface in seconds rather than reading through multiple files to infer the shape.
Mock Data Generation
Generate an interface from a fixture or seed file and use it to type your test mocks. TypeScript will warn you when a mock is missing a required field.
Third-Party SDK Typing
When a third-party SDK returns untyped any objects, paste a logged response into the generator to produce a compatible interface and cast the result safely.
Generated Interface Examples
Simple flat object
JSON input
{
"id": 42,
"name": "Alice",
"active": true
}TypeScript output
interface Root {
id: number;
name: string;
active: boolean;
}Array with optional fields
JSON input
[
{ "id": 1, "name": "Alice", "role": "admin" },
{ "id": 2, "name": "Bob" }
]TypeScript output
// Top-level JSON is an array: Root[]
interface Root {
id: number;
name: string;
role?: string;
}Nested objects
JSON input
{
"user": {
"id": 1,
"address": {
"city": "New York"
}
}
}TypeScript output
interface Root {
user: User;
}
interface User {
id: number;
address: Address;
}
interface Address {
city: string;
}Limitations to Be Aware Of
- ⚠Single sample: Inference is based on the values in the JSON you provide. If an API sometimes returns a field and sometimes omits it, use multiple samples or mark the field optional manually.
- ⚠Null widens to null only: A field that is
nullin the sample gets typenull. If the field can also be a string in other responses, change it tostring | nullmanually. - ⚠No integer vs float distinction: JSON numbers — whether integers or decimals — all map to
numberin TypeScript since JavaScript makes no distinction. - ⚠Enum detection: String fields that are actually enums (e.g.,
"status": "active") generate asstring. Narrow them to a union type or enum manually if needed.
Frequently Asked Questions
How do I convert JSON to a TypeScript interface?
Paste your JSON into the input box, optionally set a root interface name, and click Generate Interfaces. The tool produces ready-to-use TypeScript interface definitions that match the exact shape of your JSON.
Does the generator handle nested objects?
Yes. Each nested object becomes its own named interface. For example, an "address" field containing "street", "city", and "zip" generates a separate Address interface, and the parent interface references it by name.
How are arrays handled?
Arrays of primitive values produce types like string[] or number[]. Arrays of objects are merged into a single interface — all keys are collected, and any key that does not appear in every element is marked as optional with a ? suffix.
What happens with null values?
A JSON field that is null produces a null type (e.g., metadata: null). If you need to accept both a value and null in your actual code, edit the generated interface to add the union manually: metadata: string | null.
Is my JSON sent to a server?
No. All type inference runs entirely in your browser using JavaScript. Your JSON data never leaves your device and is not stored anywhere.
Can I use the generated interfaces directly in my TypeScript project?
Yes. Click Download .ts to save the interfaces as a file, or Copy to paste them directly into your editor. The output uses standard TypeScript interface syntax compatible with TypeScript 4+ and all major bundlers.
What if my JSON has keys that are not valid identifiers?
Keys containing spaces, hyphens, or other special characters are automatically quoted in the interface output (e.g., "content-type": string), which is valid TypeScript.
From the Blog
View all →5 JSON Formatter Tips for Faster API Debugging
Practical JSON formatting habits that reduce debugging time when working with API responses and logs.
How to Format JSON in JavaScript
A practical guide to formatting, validating, and safely pretty-printing JSON in modern JavaScript apps.
JSON vs XML — Which Should You Use?
A practical comparison of JSON and XML for APIs, integration workflows, and long-term maintainability.
Top 5 Free Online JSON Formatters Compared
A feature-by-feature comparison of five popular free JSON formatters, with a practical ranking for developer workflows.
