JSON to TypeScript
Generate TypeScript interfaces from JSON.
export interface Root {
id: number;
name: string;
active: boolean;
price: number;
discount: null;
tags: string[];
sizes: number[];
address: Address;
variants: (Variant | Variant2)[];
}
export interface Address {
city: string;
zip: string;
country: string;
}
export interface Variant {
sku: string;
color: string;
stock: number;
}
export interface Variant2 {
sku: string;
color: string;
stock: number;
}How to use JSON to TypeScript
What this tool does
JSON to TypeScript reads a block of JSON and writes the matching TypeScript
type declarations — the interface definitions that give a TypeScript project
autocomplete, refactoring safety and compile-time checks. Paste a JSON sample,
drop a .json or .txt file, or load the built-in example, and the tool
infers a complete set of interfaces describing that data’s shape. You can copy
the result or download it as interfaces.ts.
It saves the tedious, error-prone job of hand-typing interfaces to match an API response. Instead of squinting at a payload and transcribing every field, you paste the payload once and get a faithful starting point in seconds.
How the inference works
The generator walks your JSON and builds a type for every value:
- The root object becomes an interface named
Rootby default — you can rename it in the Root type name field. - Each nested object becomes its own named interface, with the name derived
from the key it sits under (
addressbecomesAddress,billing_infobecomesBillingInfo). Identically named shapes get a numeric suffix so every interface name stays unique. - Arrays become
T[]. The element type is inferred from the items; mixed-type lists become a union like(number | string)[], and empty lists becomeunknown[]because there is nothing to inspect. - Primitives map to
string,numberandboolean; an empty value maps tonull. - If the root of your JSON is an array or a single value rather than an object,
the tool emits a
typealias for it instead of an interface.
Options you can set
- Root type name — name the top-level type whatever your code expects.
- Output style — choose
interfacedeclarations ortypealiases. - Optional properties — leave every property required, mark only the fields
that were
nullas optional with?, or make every property optional. The last is useful for partial-update payloads where any field may be absent. - Export keyword — toggle whether each declaration is prefixed with
exportso it can be imported from other files.
How to use it
- Paste your JSON, drop a file, or load the sample.
- Set the root type name to match your codebase, and pick
interfaceortype. - Choose how optional properties should be handled.
- Decide whether the declarations should be exported.
- Read the generated code, then Copy it or Download .ts to drop
interfaces.tsstraight into your project.
If the JSON is malformed, a clear error names the problem so you can fix the source and try again.
Tips and common pitfalls
Generated types reflect one sample, not every possible response. If a field can
be missing, null, or hold more than one type, your single example will not show
that — paste a representative payload, or generate from a few samples and merge
the results. After generating, it is normal to widen a string to a union of
literals, or to mark a field optional that the sample happened to include.
Watch for invalid JSON: trailing commas, single quotes and unquoted keys are
common when JSON is copied out of source code rather than from a real response.
Numbers in JSON have no integer-versus-float distinction, so every number
becomes number — adjust by hand if you need a stricter type.
To inspect a payload before converting it, try the JSON Tree Viewer. To tidy or validate raw JSON first, use the JSON Formatter. If you need runtime validation rather than compile-time types, the JSON Schema Generator is the better fit.
Privacy
This converter runs entirely in your browser. The JSON you paste or the file you drop is parsed and turned into TypeScript by JavaScript on your own device. Nothing is uploaded, nothing is stored between visits, and nothing is logged. Close the tab and the data is gone — so generating types from real API responses here exposes nothing.
Frequently asked questions
How does the tool decide each property's type?
What happens with arrays that mix different value types?
Should I use interface or type, and when do I mark properties optional?
How is this different from a JSON schema generator?
Is my JSON private when I use this tool?
Related tools
JSON Tree Viewer
Explore JSON in a collapsible tree view.
JSON Formatter
Format, validate, and minify JSON instantly.
JSON Schema Generator
Infer a JSON Schema from a sample document.
JSON to Excel
Convert JSON data into a downloadable Excel file.
JSON to CSV
Convert JSON arrays into CSV, flattening nested data.
XML to JSON
Convert XML documents into JSON.