JSON to TypeScript Converter

Generate Interfaces, Types & Zod Schemas from JSON - Free & Private

Convert JSON to TypeScript

JSON Input 0 chars
TypeScript Output 0 chars

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 interface declarations with separate named interfaces for each nested object. Best for codebases that use interface extends.
  • Type Alias mode: Generates type aliases 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 export before each declaration (default: on).
  • Readonly: Generates readonly properties for immutability.
  • Null → optional: Treats null values as optional (?) instead of null types.
  • Root name: Customize the name of the root interface/type/schema.

Type Inference Rules

  • stringstring
  • numbernumber
  • booleanboolean
  • nullnull (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

Comments & Ratings

Be the first to comment.

References