JSON to TypeScript

Generate TypeScript interfaces from JSON

Try an example
Root interface name:

JSON Input

TypeScript Output

Runs locally Β· Safe to paste secrets
TypeScript interfaces will appear here…

What is JSON to TypeScript Conversion?

Paste a JSON payload and you get back TypeScript interfaces β€” typed contracts that describe exactly what properties an object has and what type each one holds. Without them, data from JSON.parse() arrives as any, giving you no editor assistance and no compiler checks on property access or assignment. Converting JSON to TypeScript gives you that safety without writing interfaces by hand.

TypeScript covers all six JSON value types: string, number, boolean, null, object, and array. Every nested JSON object turns into its own named interface. Arrays get typed from their first element. The result matches what JSON.parse() actually returns at runtime, so the interfaces reflect real data rather than guesswork.

Manually writing interfaces for large or deeply nested JSON is tedious and error-prone. A JSON to TypeScript generator reads the structure automatically, handles nesting recursively, and outputs clean interface code in seconds. This is especially useful when wiring up an unfamiliar API, prototyping with mock data, or migrating a JavaScript codebase to TypeScript. It also frees you from tracking nested property names and types by hand, so you can focus on application logic rather than type boilerplate.

Why Use a JSON to TypeScript Generator?

Generating TypeScript interfaces by hand is practical for small objects, but breaks down quickly with nested structures or large API responses. Consider a 50-field API response with three levels of nesting β€” writing that by hand means dozens of interfaces, each one a potential source of typos or missed nullable fields. An automated generator produces the full set in milliseconds and reduces the chance of type mismatches between your code and the data it consumes. Beyond accuracy, it keeps your types in sync with the actual API contract. When a service changes its response shape, simply paste the updated JSON and regenerate β€” far faster than hunting down every property that shifted across a handwritten interface file.

⚑
Generate interfaces instantly
Paste any JSON payload and get correctly typed interfaces in milliseconds. No configuration, no build step required.
πŸ”’
Keep data private
All conversion runs in your browser. Your JSON never leaves your machine, which matters when working with production data or internal API responses.
πŸ“‹
Handle nested structures automatically
Nested objects produce separate named interfaces. Arrays, nullable fields, and mixed types are all resolved without manual intervention.
🌐
No account or installation
Works in any modern browser. No npm packages to install, no CLI tools to configure, no sign-up forms to fill out.

JSON to TypeScript Use Cases

Frontend API Integration
Paste a REST or GraphQL JSON response to generate interfaces for your React, Angular, or Vue components. Type-safe props and state prevent runtime surprises. You can also share generated interfaces between frontend and backend in a monorepo so both sides agree on the same data shape.
Backend Response Typing
Node.js and Deno services that consume third-party APIs benefit from generated interfaces. Define the contract once, catch shape mismatches at compile time. Generated interfaces are also lightweight documentation for service consumers, reducing the need for separate schema files or wiki pages.
DevOps Configuration Files
Infrastructure tools like AWS CDK or Pulumi use JSON configs. Generate TypeScript types for those configs to validate them before deployment. This catches misconfigured deployments caused by typos or wrong value types before code reaches production.
QA Test Fixtures
Generate interfaces from JSON test fixtures so your assertions match the expected data shape. Catch missing or renamed fields before tests run.
Data Pipeline Contracts
When a pipeline produces JSON output, generated interfaces act as a schema for downstream consumers. Changes to the output shape trigger compile-time errors.
Learning TypeScript
Students and developers new to TypeScript can paste familiar JSON structures and see how interfaces map to data. It bridges the gap between dynamic and static typing.

JSON to TypeScript Type Mapping Reference

Every JSON value maps to a TypeScript type. The table below shows how each JSON primitive and structural type translates. This mapping follows the ECMA-404 JSON standard and TypeScript's built-in types.

JSON TypeExample ValueTypeScript Type
string"hello"string
number42, 3.14number
booleantrue, falseboolean
nullnullnull
object{"key": "value"} nested interface
array[1, 2, 3]number[] (inferred from first element)

TypeScript interface vs type Alias

TypeScript offers two ways to describe object shapes: interface declarations and type aliases. Both work for representing JSON structures, but they differ in extension and merging behavior. Most JSON-to-TypeScript generators output interfaces because they are the idiomatic choice for object shapes in TypeScript.

interface
Supports declaration merging and extends syntax. Preferred for object shapes, especially in public APIs and libraries. Can be extended by other interfaces or intersected with types.
type
Supports union types, intersection types, and mapped types. Better suited for computed types, discriminated unions, or when you need to alias a primitive. Cannot be reopened for declaration merging.

Code Examples

Below are examples of generating TypeScript interfaces from JSON in different languages and tools. Each snippet produces runnable output.

TypeScript
// Manual interface definition from a JSON shape
const json = '{"id": 1, "name": "Alice", "active": true}';
const parsed = JSON.parse(json);

interface User {
  id: number;
  name: string;
  active: boolean;
}

const user: User = parsed;
console.log(user.name); // "Alice" β€” fully typed
JavaScript (json-to-ts library)
import JsonToTS from 'json-to-ts';

const json = {
  id: 1,
  name: "Alice",
  address: { street: "123 Main St", city: "Springfield" },
  tags: ["admin", "user"]
};

const interfaces = JsonToTS(json, { rootName: "User" });
console.log(interfaces.join("\n\n"));
// interface Address {
//   street: string;
//   city: string;
// }
//
// interface User {
//   id: number;
//   name: string;
//   address: Address;
//   tags: string[];
// }
Python (datamodel-code-generator)
# Install: pip install datamodel-code-generator
# Generate TypeScript-style types from JSON using Pydantic models

# Command line:
# datamodel-codegen --input data.json --output model.py

# Or generate TypeScript directly with quicktype:
# pip install quicktype
# quicktype --lang ts --src data.json --out types.ts

import json

data = {"id": 1, "name": "Alice", "scores": [98, 85, 92]}

# Python equivalent using TypedDict (Python 3.8+)
from typing import TypedDict, List

class User(TypedDict):
    id: int
    name: str
    scores: List[int]

user: User = data  # type-checked by mypy
CLI (quicktype)
# Install quicktype globally
npm install -g quicktype

# Generate TypeScript interfaces from a JSON file
quicktype --lang ts --src data.json --out types.ts

# From a JSON string via stdin
echo '{"id": 1, "name": "Alice"}' | quicktype --lang ts

# Output:
# export interface Root {
#   id:   number;
#   name: string;
# }

Frequently Asked Questions

How does JSON to TypeScript handle optional fields?
If a JSON value is null, the generator marks the property as optional with a ? suffix and assigns the null type. If you need to distinguish between missing keys and null values, you can manually adjust the output to use undefined for missing properties.
Can I convert JSON arrays to TypeScript?
Yes. If your root JSON is an array, the generator inspects the first element to infer the item type and outputs an interface for that element. The root type becomes that interface followed by []. Empty arrays produce unknown[] since there is no element to inspect.
What happens with deeply nested JSON objects?
Each nested object generates a separate named interface. The name is derived from the property key, converted to PascalCase. For example, a property called "shipping_address" produces an interface named ShippingAddress. This keeps the output readable even for JSON with four or five levels of nesting. If multiple nested objects share the same structure, you may want to manually consolidate them into a single shared interface to reduce duplication in your codebase.
Is there a difference between json2ts and quicktype?
json2ts is a simple converter that maps JSON values to TypeScript interfaces directly. quicktype goes further by analyzing multiple JSON samples, deduplicating similar shapes, and supporting output in over 20 languages. For one-off conversions, a browser-based tool is faster. For CI pipelines or multi-language codegen, quicktype is the better fit.
Why use interfaces instead of type aliases for JSON?
Interfaces support declaration merging, which means you can extend a generated interface in a separate file without modifying the original. They also produce clearer error messages in most editors. Type aliases are better when you need union types or mapped types, but for straightforward JSON object shapes, interfaces are the standard choice. If you are authoring a library or SDK, interfaces are almost always the right pick because downstream consumers can augment them with declaration merging without touching your source.
Can this tool handle JSON with inconsistent types in arrays?
The generator infers the array element type from the first non-null element. If your array contains mixed types β€” for instance, objects mixed with strings β€” the output reflects only the first element's shape. For heterogeneous arrays, you need to manually define a union array type after generation, such as a type that accepts both Item and string elements, to accurately represent all possible element types.
How do I use generated interfaces in a real project?
Copy the generated interfaces into a .ts file in your project, typically under a types/ or models/ directory. Import them where you fetch or process JSON data. Pair them with a runtime validator like Zod or io-ts if you need to guarantee that API responses match the interface at runtime, not just at compile time. With Zod, you can derive the TypeScript type directly from the schema using its infer utility, eliminating duplication between your interface definition and your validation logic.
Do generated TypeScript interfaces provide runtime type safety?
No β€” TypeScript's type system is erased at compilation. Interfaces exist only in your editor and during the build, not at runtime. JSON.parse() always returns any regardless of the type you assign afterward. To enforce types at runtime, pair your generated interfaces with a library like Zod or io-ts. These libraries validate that an incoming object actually matches the expected shape before you use it, protecting against malformed API responses, missing fields, and unexpected null values.