JSON → TypeScript

Paste any JSON object and instantly get a fully-typed TypeScript interface. Supports nested structures, arrays, optional fields, and custom naming. Everything runs in your browser — nothing leaves your machine.

Root name
Optional fields
Use type alias
Semicolons
Export keyword
Input · JSON
Output · TypeScript
❤️ Support CodeConverter.net and donate ❤️

Everything you need to know about JSON to TypeScript conversion

Why convert JSON to TypeScript interfaces?

TypeScript's type system is one of its greatest strengths — it catches type errors at compile time, improves IDE auto-completion, and documents your data structures as code. When working with REST APIs, configuration files, or database schemas, you typically receive JSON at runtime. Defining TypeScript interfaces for that JSON means every field access is validated by the compiler, refactors are safe, and future developers (including you, six months from now) immediately understand what data a function expects.

Manually writing interfaces for complex, deeply nested JSON objects is tedious and error-prone. This tool analyses your JSON's structure, infers the correct TypeScript types for each field (string, number, boolean, null, arrays, or nested objects), and emits clean, ready-to-paste TypeScript — in seconds.

Supported TypeScript types
  • Primitivesstring, number, boolean, null
  • Arrays — typed as T[] with inferred item type
  • Nested objects — generate sub-interfaces automatically
  • Empty arrays / objects — typed as unknown[] / Record<string, unknown>
100% private & client-side
  • All conversion happens inside your browser
  • Zero data transmitted to any server
  • Safe for internal API schemas & confidential data
  • Works offline after initial page load
How to use this tool
  • Paste your JSON or click Sample to try an example
  • Set the root interface name and toggle output options
  • Click Generate TypeScript
  • Copy the result or download as .ts
interface vs type
  • interface — preferred for object shapes, supports declaration merging
  • type — more flexible, supports unions & intersections
  • Toggle between both outputs with the Use type alias switch
  • Most style guides prefer interface for API response shapes
Optional fields explained
  • Enable the Optional fields toggle to add ? to all properties
  • Useful when API responses may omit certain keys
  • Results in key?: string instead of key: string
  • null-valued fields automatically get T | null type
Beyond this tool
  • For runtime validation, combine with zod or io-ts
  • Use JSON.parse with a type cast: JSON.parse(data) as Root
  • For OpenAPI / Swagger schemas, consider openapi-typescript
  • Rename sub-interfaces to match your domain model for clarity

How does the type inference work?

The converter walks the parsed JSON tree recursively. Each value's JavaScript typeof result maps to a TypeScript type: "string"string, "number"number, "boolean"boolean. A null value becomes T | null (or just null if no other samples exist). Arrays are inspected for their element types — if all items share the same shape, the item type is inferred; mixed-type arrays fall back to unknown[].

Nested objects generate separate named interfaces. The name is derived from the parent key in PascalCase — so a JSON field "userProfile" produces an interface named UserProfile. The root interface uses whatever name you enter in the Root name field, defaulting to Root. All sub-interfaces are emitted in dependency order so the output is copy-paste ready without any reordering.