JSON to TypeScript
Generate TypeScript interfaces or type aliases from JSON.
Related Tools
Generate Go structs with JSON tags from a JSON document.
Generate Python dataclasses from a JSON document.
Generate a Zod validation schema and TypeScript type from a JSON document.
Beautify and pretty-print JSON with configurable indentation.
Validate JSON against a JSON Schema with JSON-pointer error paths.
Generate a Java POJO class with getters and setters from a JSON document.
Documentation
What is JSON to TypeScript?
This tool converts a JSON sample into one or more TypeScript interface declarations. Instead of hand-writing types for an API response or config file, you paste real JSON and get back the matching shape, including separate interfaces for every nested object it finds.
How it works
The converter walks the JSON value tree once, inferring a type node for every key: strings, numbers, booleans, arrays (typed from their first element), and nested objects (each given its own PascalCase name derived from its key). It then emits one interface per object node, printing child interfaces before the parents that reference them so the output reads top-down without forward references. A field whose sample value was null is marked optional with ? and typed as unknown rather than guessed at.
Features
- Nested objects become separate, named
interfacedeclarations instead of one deeply-nested inline type - Arrays are typed as
T[]using the inferred element type - Non-identifier keys (e.g. containing spaces or dashes) are quoted automatically so the interface stays valid
- Nullable sample values are typed
unknownand marked optional rather than forced into a guessed type - Runs entirely client-side — nothing you paste is uploaded
Example
Input: { "id": 101, "username": "alice_dev", "isActive": true, "signupBonus": null, "address": { "city": "Berlin", "zipCode": "10115" }, "tags": ["admin", "beta"] }
Output:
export interface Address {
city: string;
zipCode: string;
}
export interface Root {
id: number;
username: string;
isActive: boolean;
signupBonus?: unknown;
address: Address;
tags: string[];
}Common errors
Invalid JSON (trailing commas, unquoted keys) is caught before conversion and reported with a line number. Because the tool infers types from one sample, an array whose real-world elements vary in shape won't produce a union — pass a representative element, or widen the field type by hand afterward. Empty arrays have no element to infer from and fall back to unknown[].
Best practices
Prefer unknown over widening to any for fields the tool couldn't infer — it forces you to narrow the type before use instead of silently disabling type checking. Feed the tool a JSON sample that already includes at least one non-null value for every field so optionality and element types come out accurate, then adjust manually for fields that are truly optional versus merely null in your sample.
Frequently Asked Questions
Interface vs type — which should I pick?▾
Both describe the same shape. interface is more common for object shapes and supports declaration merging; type is more flexible for unions and computed types. Pick whichever matches your codebase's convention.
When does a field become optional?▾
A field is marked optional (with ?) when its sample value is null, since the tool infers from a single example rather than scanning every array element for presence.
What's the difference between unknown and any?▾
unknown is the type-safe choice — you must narrow it before using it. any opts out of type checking entirely. Prefer unknown unless you have a specific reason not to.
How are nested objects named?▾
Each nested object gets its own named interface/type derived from its key (PascalCased), so deeply nested JSON produces multiple readable declarations instead of one giant inline type.
Does array element type get inferred correctly?▾
The tool infers the array's element type from its first item. Arrays with mixed element shapes across items aren't merged into a union — keep sample arrays representative.