JSON to TypeScript Interface Generator
Paste any JSON object or array and this tool infers matching TypeScript type definitions
Paste any JSON object or array and this tool infers matching TypeScript type definitions
How to use JSON to TypeScript Interface Generator
- Paste your JSON object or array into the input box.
- Set the root name and choose interface or type, null handling, and export options.
- Copy the generated TypeScript interfaces into your project.
About JSON to TypeScript Interface Generator
Paste any JSON object or array and this tool infers matching TypeScript type definitions. Nested objects each become their own named interface, arrays of objects are merged into a single shape so every key seen across the items is captured, and keys that are missing from some items (or that are sometimes null) are marked optional. You can choose interface or type-alias output, add or drop the export keyword, name the root type, and pick whether null becomes a "| null" union member or an optional key.
Type inference is based only on the sample you paste, so it is as accurate as your data is representative. A field that only ever shows a whole number becomes number, an empty array becomes unknown[], and a key that is always null becomes null (or optional). If your real API can return values the sample never shows, review and widen the generated types by hand. Property keys that are not valid JavaScript identifiers are automatically quoted.
Everything runs locally in your browser with plain JavaScript. Your JSON is never uploaded, logged, or sent anywhere, which makes it safe to use with API responses or payloads that contain private data.
Frequently asked questions
- How does it decide which fields are optional?
- When you paste an array of objects, the tool merges every item into one shape. Any key that is absent from at least one item is marked optional with a question mark. A key that is present everywhere but sometimes null is treated according to the null-handling option you choose.
- Does it handle nested objects and arrays?
- Yes. Each nested object becomes its own named interface, referenced by the parent. Arrays of objects are unified into a single element interface, and arrays of mixed primitive values become a union type such as (string | number)[].
- What happens with null or empty values?
- You can set null to become a union member (value: string | null) or an optional key (value?: string). Empty arrays become unknown[] and empty objects become Record<string, unknown>, since there is no sample data to infer a specific type from.
- Is my JSON sent to a server?
- No. All parsing and type inference happens entirely in your browser using JavaScript. Nothing is uploaded, stored, or transmitted, so it is safe for sensitive API responses.
- How accurate are the generated types?
- The types reflect exactly the sample you paste. If your data source can return additional fields or different value types that are not in your sample, the tool cannot know about them, so review and adjust the output for real-world edge cases.
- Can I output type aliases instead of interfaces?
- Yes. Switch the output style to type alias to get `type Name = { ... }` blocks instead of `interface Name { ... }`. You can also toggle the export keyword and rename the root type.