JSON to TypeScript

Generates TypeScript interfaces from sample JSON, giving nested objects their own named interfaces and marking keys absent from some array items as optional. You choose the root name; in-browser.

Last updated:

Paste your JSON here...
Loading editor...
Loading editor...

JSON to TypeScript Interfaces — Generate Types from JSON

Understanding the Basics

TypeScript has become the dominant language for large-scale JavaScript projects, and one of its most powerful features is static type checking through interfaces and type aliases. When working with external JSON APIs, developers must either write TypeScript interfaces manually (tedious and error-prone) or use any (which defeats TypeScript's purpose). Generating TypeScript types automatically from a sample JSON response is a productivity multiplier: a 200-key API response that would take an hour to type manually can be converted in seconds. The generated interfaces accurately reflect the structure of the sample data: nested objects produce nested interfaces, arrays of objects produce typed array interfaces, optional keys (present in some but not all sample records) are marked with the ? optional modifier, and primitive types (string, number, boolean) are inferred correctly. Our tool uses the quicktype-core library — the same engine used by the popular VS Code extension "Paste JSON as Code" — which produces idiomatic TypeScript interfaces with proper naming conventions. Classes, enums, and union types are also generated for complex schemas.

How to Use the Tool

  1. Paste a JSON object or array of objects representing your API response.
  2. Enter a name for the top-level interface (e.g., "ApiResponse" or "User").
  3. The tool infers the structure and generates TypeScript declarations as you type.
  4. Review the output: nested objects become additional named interfaces, arrays become typed arrays.
  5. Copy the interfaces and paste them into your TypeScript project's types file.

Key Features & Specifications

  • Infers object properties and array item types from the input
  • Generates proper TypeScript interfaces with accurate primitive types
  • Detects optional fields when analyzing multiple JSON samples simultaneously
  • Nested objects produce separate named interfaces for clean code organization
  • Outputs idiomatic TypeScript with camelCase property names where detected

Frequently Asked Questions (FAQ)

Q:How does the tool determine if a field is optional?
When a JSON array contains several records, the tool marks fields present in only some records as optional (key?: type). With a single sample, all fields are treated as required. Providing multiple diverse samples produces more accurate optional detection.
Q:Can I generate Zod schemas instead of TypeScript interfaces?
The current implementation focuses on TypeScript interfaces. For Zod schema generation, you can use the interfaces as a reference and write the Zod schema alongside them — or use the quicktype CLI locally with the --lang zod option.
Q:Will the generated types work in JavaScript projects?
TypeScript interfaces are erased at compile time and have no runtime impact. For JavaScript-only projects (without a build step), you can use JSDoc type comments instead, or simply use the interfaces as documentation while writing plain JavaScript.