JSON to TypeScript - Generate Interfaces from JSON
From an API response to types
Most people reach for this when a new endpoint lands and the only documentation is a response body. Paste the
JSON on the left and you get one TypeScript declaration per object shape on the right, named after the key that
holds it. Keys that aren't valid identifiers, such as "+1" or "first-name", are kept as
quoted property names so the type still matches the payload.
Example: a GitHub-style issue
Input, with the root type name set to Issue:
{
"id": 4211,
"title": "Fix login redirect",
"labels": ["bug", "auth"],
"assignee": null,
"author": { "login": "ada", "site_admin": false },
"comments": [
{ "id": 1, "body": "Repro steps attached", "edited_at": null },
{ "id": 2, "body": "Fixed in #4212", "reactions": { "+1": 3 } }
]
} Output:
export interface Issue {
id: number;
title: string;
labels: string[];
assignee: null;
author: Author;
comments: Comment[];
}
export interface Comment {
id: number;
body: string;
edited_at?: null;
reactions?: Reactions;
}
export interface Reactions {
"+1": number;
}
export interface Author {
login: string;
site_admin: boolean;
}
The two comments are merged into a single Comment interface. reactions is only on the
second one, so it gets ?. edited_at is only on the first one and only ever null, so it
comes out as edited_at?: null. That is accurate for this sample and wrong for your app, and the same
goes for assignee. Fix those by hand or paste a richer sample. Property names are not renamed:
site_admin stays snake_case because that is what arrives over the wire.
Options
Declare as switches every declaration between interface Author { } and
type Author = { };. Export adds or removes the export keyword.
Readonly prefixes each property with readonly, which suits data you only read
from a cache or store. All properties optional puts ? on everything, handy for a
PATCH body; for the same type in both forms you can also keep it off and use Partial<Issue>.
What it won't guess
Numbers are always number, even for IDs too big for a JavaScript double. A string like
"open" stays string rather than a literal union, because three samples are not enough
to know the full set of values. Date strings stay string too, since JSON.parse
never gives you a Date. Objects with no keys become Record<string, unknown>.
If you turn on exactOptionalPropertyTypes in your tsconfig, reactions?: Reactions no
longer accepts an explicit undefined. That matches JSON, which has no undefined, so the generated
types work under that flag without changes.
Types are compile-time only. To check a response at runtime, use the JSON to Zod page with the same input, or create a JSON Schema if another service or language needs to share the contract.
Same JSON, other languages
Every generator here reads the sample the same way, so a key that is optional or nullable in one language is optional or nullable in the others. Paste the same input into: Zod, Go, Python, Rust, Java, C#, JSON Schema.
Related Tools
JSON to YAML Converter
Convert JSON data to clean, readable YAML format instantly.
JSON to XML Converter
Transform JSON objects and arrays into well-formed XML documents.
JSON to CSV Converter
Flatten JSON arrays into downloadable CSV spreadsheets in one click.
YAML to JSON Converter
Convert YAML configuration files to JSON format instantly.