JSON to TypeScript
Paste JSON and instantly get clean TypeScript interface definitions with inferred types for nested objects and arrays.
Example
Given this JSON:
{"id":1,"name":"Ada","profile":{"city":"London"}}the tool emits:
export interface Root {
id: number;
name: string;
profile: Profile;
}
export interface Profile {
city: string;
}How it works
It parses your JSON, infers each value's type, and emits TypeScript interfaces — the top level becomes Root and every nested object becomes its own named interface. Arrays of objects are merged so all keys appear, with optional union types for mixed elements.
Good to know
JSON to TypeScript turns a raw JSON payload into a set of ready-to-paste TypeScript interface definitions. It walks the structure, infers each value's type, names the top-level object Root, and pulls every nested object out into its own named interface so you don't have to type them by hand. It's aimed at frontend and backend developers who consume APIs and want compile-time safety without writing boilerplate types from a sample response.
Reach for it when you have an example API response, a config file, or a fixture and want a typed shape to drop into a codebase — for instance, to type a fetch result, seed a DTO, or sanity-check what a third-party endpoint actually returns versus its docs. Because it works from a real sample, the output reflects the data you actually got, which often catches fields the documentation forgot to mention.
When reading the result, remember that the types are inferred from one sample, not from a schema. A few signals are worth checking: any means the source value was null; any[] means an array was empty so nothing could be inferred; a union like (Post | number)[] means an array held mixed element types; and for arrays of objects, all keys seen across elements are merged into a single interface, so a key that appeared in only some elements will still show up as required.
- Feed it the most complete sample you can — a record with every optional field populated and arrays that are non-empty — so it doesn't fall back to
any or miss keys, then hand-edit anything that should be optional (?) or nullable once you have the generated baseline.
Frequently asked questions
How are arrays of objects handled?
Objects inside an array are merged so every key seen across elements appears in one interface, and the field is typed as that interface followed by [] (e.g. Post[]). Keys present in only some elements still appear.
What happens with null or empty arrays?
A null value is typed as any, and an empty array is typed as any[], since there is no data to infer a more specific type from.
Is my data uploaded anywhere?
No — it runs entirely in your browser. Your input never leaves your device and it works offline once loaded.
Is it free?
Yes, completely free with no sign-up and no limits.
People also ask
Does JSON to TypeScript mark fields as optional?
No. It infers types from a single sample and emits every key as a required field, including keys that appeared in only some array elements. If a field can be absent or undefined, add the ? modifier yourself after generating.
Why is a field typed as 'any' instead of a real type?
A value of any means the source value was null in your sample, so there was no data to infer from. Similarly, an empty array becomes any[]. Provide a sample where those fields are populated to get a more specific type.
What is the difference between a TypeScript interface and a type alias?
An interface declares the shape of an object and can be extended or merged, while a type alias can describe objects plus unions, primitives, and tuples but cannot be reopened. This tool emits interfaces for objects and falls back to a type alias only when the root is not an object.
Can it generate types from an array at the top level?
Yes. If the root is an array, the tool infers the element type, merges object elements into a shared interface, and produces a Root type alias such as export type Root = Post[] when the root itself is not a plain object.
How does it handle arrays that contain mixed types?
It produces a union of the element types followed by [], for example (string | number)[]. Object elements in the array are merged into one interface so all keys across elements appear in a single type.
Is the generated TypeScript safe to paste directly into my project?
The output is valid TypeScript, but it reflects only the sample you provided. Review optional and nullable fields, rename the auto-generated Root and singularized nested interface names to fit your conventions, and tighten any any types before relying on it.
Does converting JSON to TypeScript send my data to a server?
No. The conversion runs entirely in your browser using client-side JavaScript, so the JSON you paste never leaves your device and the tool continues to work offline once the page has loaded.
How are nested object keys converted into interface names?
Each nested object becomes its own interface named after its key, converted to PascalCase, and array element keys are singularized (for example posts becomes Post). If two different shapes would collide on the same name, a numeric suffix is appended to keep them distinct.
Related tools