JSON to TypeScript Converter & Interface Generator
Turn a JSON document or API response into copy-ready TypeScript interfaces or type aliases. Nested objects get their own names, arrays of records are merged and missing fields become optional. Everything runs locally in your browser.
Your text never leaves your browser.
TypeScript output
Paste a JSON object, array or API response, or load the sample. Interfaces appear here as you type.
Generation options
Used exactly as typed for the top-level declaration.
Summary
- Status
- —
- Top-level type
- —
- Declarations
- —
- Properties
- —
Waiting for input: paste JSON or load the sample.
Types reflect only this sample. Required fields and value types are not guaranteed by your API contract.
How JSON to TypeScript conversion works
Paste a JSON document, such as an API response, and the converter parses it with the browser's strict JSON parser, walks every value and records the type it observes: string, number, boolean, null, array or object. Each nested object becomes its own named declaration, and the root declaration comes first. The output uses two-space indentation and semicolons, keeps your property order and is regenerated as you type.
{
"id": 1,
"name": "Ana",
"profile": {
"city": "Vilnius"
},
"tags": ["a", "b"]
}export interface Root {
id: number;
name: string;
profile: Profile;
tags: string[];
}
export interface Profile {
city: string;
}Your JSON must be strict: comments, trailing commas and single quotes are errors. If the parser reports a problem, tidy the document in the JSON Formatter & Validator first, or convert a configuration file with the YAML to JSON Converter.
Interfaces versus type aliases
For object shapes, interface User { … } and type User = { … }; are interchangeable in everyday code. Interfaces can be extended with extends and merged by a later declaration of the same name, which libraries use to let you augment their types. Type aliases can also name unions, tuples and primitives. Pick whichever your project already uses. When the top-level JSON value is an array or a primitive, the root is always a type alias, such as export type Root = boolean[];, because an interface can only describe an object.
Nested JSON and declaration names
A nested object is named after its property key in PascalCase, so profile becomes Profile and billing_address becomes BillingAddress. Objects inside an array named users become UsersItem. If two keys would produce the same name, the later one gets a numeric suffix such as Profile2, and names that clash with built-ins like Date or Map are suffixed too. Names are never taken from values. Keys that are not valid identifiers, such as "user-id", are kept exactly and written as quoted, escaped property names.
How arrays are merged
All objects in an array are merged into one element type, so a list of users produces a single UsersItem instead of one declaration per record. Nested objects inside those records are merged the same way. Arrays that mix kinds of values become unions in the order they first appear, for example [1, "a", null] becomes (number | string | null)[]. An empty array gives unknown[] because there is nothing to infer from. Nested arrays keep their dimensions, such as number[][].
{
"users": [
{ "id": 1, "name": "Ana" },
{ "id": 2, "active": true }
]
}export interface Root {
users: UsersItem[];
}
export interface UsersItem {
id: number;
name?: string;
active?: boolean;
}Optional versus nullable properties
These are different things. An optional property, written name?: string, may be missing from the object entirely. A nullable property, written name: string | null, is always present but can hold null. The generator marks a property optional when it is absent from at least one object in a merged array, and adds null to the union when it sees a null value. A property that is only ever null is typed null, and the summary lists it so you can widen it to the real type.
Limitations of inference from a sample
A sample shows what one response looked like, not what the API promises. A field present in every sampled record is required in the output, but it may be optional in the real contract. Strings are never narrowed to literal values, enums, dates, URLs, UUIDs or emails, and numbers are never narrowed to integers, because one example cannot prove those rules. JSON is parsed into JavaScript numbers, so integers larger than 9007199254740991 may lose precision, and numbers outside JavaScript’s finite range become infinity; the type is still number. Integer-like keys are listed first, as JavaScript orders them, and a repeated key keeps its last value. Inputs are limited to 500,000 characters, 20,000 values and 60 levels of nesting; larger samples are rejected with a message rather than truncated.
TypeScript types versus runtime validation
TypeScript types disappear when your code is compiled. Casting a fetch response to Root tells the compiler what to expect but checks nothing at runtime, so a changed API can still break your app. For data you do not control, validate it at runtime too, for example with a Zod schema from the JSON to Zod Schema Generator or against a JSON Schema. You can test payloads against a schema with the JSON Schema Validator, and inspect tabular API data with the JSON to CSV Converter.
Privacy and local processing
Type generation runs entirely in your browser. Your JSON is parsed with JSON.parse, never evaluated, and the generated code is never executed. Nothing is uploaded, logged, stored, placed in the URL or sent to analytics, and the .ts download is created locally on your device.
Frequently asked questions
Why is a field typed as null instead of string | null?
The generator only knows what appears in your sample. If a field is null in every record it saw, the only type it can prove is null. Edit the declaration to the real type, for example string | null, or paste a sample where the field has a value.
Why did a property become optional?
When an array contains several objects, they are merged into one element type. A property that is missing from at least one of those objects is marked optional with ?. Properties present in every sampled object stay required, but that only reflects your sample, not a guarantee from the API.
Should I use interfaces or type aliases?
For plain object shapes both work the same in day-to-day code. Interfaces can be extended and merged by later declarations and give slightly clearer error messages; type aliases can also name unions, arrays and primitives. Follow your codebase convention. Top-level arrays and primitives always use a type alias because an interface cannot describe them.
Why are dates, emails and IDs typed as string?
JSON has no date, URL or UUID type, so these values arrive as strings. The generator does not guess formats or literal values such as "active", because a single sample cannot prove which values are allowed. Narrow them by hand, for example to a union of string literals, when you know the contract.
Do the generated types validate data at runtime?
No. TypeScript types are erased when your code is compiled, so a response that does not match the declarations will not throw. Validate untrusted data at runtime with a schema, for example JSON Schema or a validation library, and use the generated types for editor support and compile-time checks.
Are large numbers and key order kept exactly?
Every number is typed as number. Parsing uses JavaScript numbers, so integers beyond 9,007,199,254,740,991 may lose precision, and numbers outside the finite range become infinity. The tool warns about these cases; send exact large values as strings. Key order follows JavaScript object rules: integer-like keys such as "1" come first in ascending order, then other keys in the order written. If a key is repeated, the last value wins.
How are unusual property names handled?
Keys that are valid identifiers are written as-is. Keys with spaces, hyphens, quotes or other characters are written as escaped string literals, so "user-id" stays "user-id". Declaration names are derived from keys in PascalCase and never from values; when a safe name cannot be derived the tool uses NestedType, and repeated names get numeric suffixes such as Profile2.
Is my JSON sent anywhere?
No. Parsing and type generation run in your browser. Your JSON and the generated code are not uploaded, logged, stored, added to the URL or sent to analytics. Downloads are created locally.