Convert JSON to TypeScript
Turn JSON API Responses into TypeScript Types — Instantly
Every time you copy a JSON response from an API and need TypeScript interfaces for it, you face a choice: write them by hand (slow, error-prone for deep nesting), ask an AI chatbot (hallucinates types, invents fields, gets array element types wrong), or install a CLI tool (requires npm, not always available). This tool gives you a fourth option — paste JSON, get deterministic TypeScript output, zero setup, zero privacy risk.
Why AI Cannot Do This Reliably
Large language models are probability engines, not compilers. When asked to generate TypeScript types from JSON, they commonly produce these errors:
- Wrong array types: An array of mixed numbers and strings becomes
any[]instead of(string | number)[] - Missing nested interfaces: Deeply nested objects get flattened into inline types, losing readability
- Invented fields: AI sometimes adds properties that don't exist in the source JSON
- Inconsistent naming: Each generation produces different interface names
- Zod schema errors: Methods like
z.array()are wrapped incorrectly or missing required imports
This tool uses deterministic traversal — it reads every key, infers every type from actual values, and produces identical output for identical input every time. No hallucination, no variation.
Three Generation Modes
- Interface mode: Generates TypeScript
interfacedeclarations with separate named interfaces for each nested object. Best for codebases that use interface extends. - Type Alias mode: Generates
typealiases instead of interfaces. Best for union types, intersection types, and when you prefer type aliases. - Zod Schema mode: Generates Zod validation schemas with
z.object(),z.string(),z.number(),z.array(), etc. Includes proper Zod import statement.
Options
- Export keyword: Adds
exportbefore each declaration (default: on). - Readonly: Generates
readonlyproperties for immutability. - Null → optional: Treats
nullvalues as optional (?) instead ofnulltypes. - Root name: Customize the name of the root interface/type/schema.
Type Inference Rules
string→stringnumber→numberboolean→booleannull→null(or optional if checked)[]→unknown[](empty array)[1, 2, 3]→number[][1, "a"]→(number | string)[]{...}→ nested interface/type/schema[{...}]→InterfaceName[]
Frequently Asked Questions
Is my JSON data sent to a server?
No. All processing happens entirely in your browser using JavaScript. Your JSON never leaves your device. You can disconnect from the internet after the page loads and the tool still works.
Can this handle deeply nested JSON objects?
Yes. The tool recursively traverses the entire JSON structure and generates separate named interfaces/types/schemas for every nested object. There is no depth limit.
How does it handle arrays with mixed types?
The tool collects all unique types in the array and generates a union type. For example, [1, "hello", true] produces (number | string | boolean)[].
Can I use the generated code directly in my project?
Yes. The output is valid TypeScript. For Zod schemas, you need to have zod installed in your project (npm install zod).
Is there a size limit for the JSON input?
There is no hard limit, but browser memory constraints apply. For very large JSON files (megabytes), the browser may slow down. The tool works fine for typical API responses up to several hundred kilobytes.
Related Tools
- JSON Formatter & Validator — Format, minify and validate JSON
- JSON Schema Validator — Validate JSON against a JSON Schema
- JSON to CSV Converter — Convert JSON to CSV and back
- YAML Validator — Validate and format YAML
Comments & Ratings