🔷 JSON to TypeScript -- Instant Interface Generator, Free & Offline
Paste any JSON object or array and this tool instantly generates TypeScript interface (or type alias) definitions -- completely free, no login, no upload, and runs 100% in your browser. Nested objects become nested interfaces, object arrays are merged into a single typed shape with optional fields, and mixed-type arrays produce union types automatically.
About
This JSON-to-TypeScript converter uses a pure client-side type-inference walker -- no external libraries, no server calls. It recursively visits every node in your JSON: primitive values map to string, number, boolean, or null; nested objects produce named child interfaces; arrays of objects merge all element shapes so keys missing from some elements become optional (key?: Type); arrays of mixed types produce union types such as (string | number)[]. You can choose between interface and type alias output, and set the root interface name. All work stays in your browser -- your JSON data is never sent anywhere.
How to use
- Paste your JSON into the input field -- objects, arrays, or nested structures all work.
- Set the root interface name (default: RootObject) and choose interface or type alias output.
- Click Convert to TypeScript (or press Ctrl+Enter) to generate the definitions instantly.
- Review the TypeScript output -- nested interfaces appear first, the root interface last.
- Click Copy to copy the result to your clipboard and paste it directly into your TypeScript project.
FAQ
- Does this tool upload my JSON to a server?
- No. All processing happens entirely in your browser using JavaScript. Your JSON never leaves your device.
- How does it handle arrays of objects with different shapes?
- All element shapes are merged into one interface. Keys present in every element are required; keys missing from any element are marked optional with ?.
- What is the difference between interface and type output modes?
- interface uses TypeScript interface declarations (extendable, preferred for object shapes). type uses type aliases (more flexible, supports primitives and unions at the root level). Both produce equivalent results for object shapes.
- Can it handle deeply nested JSON?
- Yes. The type walker is fully recursive -- each nested object generates its own named interface, and the interfaces are output in dependency order (deepest first) so the TypeScript compiles without forward-reference errors.
- What happens if my JSON array contains mixed types like strings and numbers?
- Mixed-type arrays produce a union type. For example, [1, 'hello', true] becomes (number | string | boolean)[]. If the array has a single consistent type, no union is needed.