JSON to TypeScript
Paste JSON and get clean TypeScript interfaces with inferred types
JSON Input
Paste a JSON object or array
TypeScript
Generated interfaces
interface Root {
id: number;
name: string;
active: boolean;
roles: string[];
profile: Profile;
posts: Post[];
}
interface Post {
title: string;
likes: number;
}
interface Profile {
age: number;
city: string;
}Examples
Convert a flat object
{"id":1,"name":"Ada","active":true}interface Root {
id: number;
name: string;
active: boolean;
}The object root becomes Root, and each observed primitive value determines its property type.
Convert an array root
[{"id":1,"name":"Ada"}]type Root = RootItem[];
interface RootItem {
id: number;
name: string;
}An array root becomes a Root type alias whose element object is named RootItem.
Preserve safe keys and quote other keys
{"2024":12,"class":"release","display name":"Ada"}interface Root {
"2024": number;
class: string;
"display name": string;
}Numeric and spaced keys are quoted, while class matches the generator's identifier pattern and remains unquoted.
About this tool
JSON to TypeScript parses a JSON value with JSON.parse and generates TypeScript declarations from the values it observes. Object roots become interfaces, array and primitive roots become type aliases, nested objects become additional interfaces, and strings, numbers, booleans, and null map to their corresponding TypeScript types. Empty arrays become unknown[], while arrays containing different observed types become union arrays.
Interface names are derived from property names with a simple PascalCase conversion. Array property names are singularized with a small set of English suffix rules, and colliding interface names receive numeric suffixes. Property names that match a JavaScript identifier pattern are emitted directly; numeric, spaced, and punctuated names are quoted with JSON string syntax.
Choose a root interface name, paste an object, array, or scalar, and the declaration updates immediately. The generator infers only from the supplied sample: every object property is required, and it does not infer optional fields, literal types, dates, enums, or application-specific semantics.
How to use
Choose the root name
Enter the name to use for the root declaration. Blank input falls back to Root, and punctuation or spaces in the name are removed by the PascalCase conversion.
Paste valid JSON
Paste a JSON object, array, or primitive into the input. Invalid JSON is reported with the message returned by JSON.parse.
Review the inferred declarations
Check primitive types, generated nested-interface names, array element unions, unknown[] results for empty arrays, and quoted property keys.
Copy and refine the TypeScript
Copy the generated output, then add optional markers, reusable domain types, literal unions, or other constraints that cannot be learned from one JSON sample.
Use cases
Typing an API response sample
Turn a captured JSON response into an initial set of interfaces before refining it against the API contract.
Scaffolding fixture types
Generate declarations from JSON fixtures used in tests, demos, or local development data.
Exploring unfamiliar payloads
Reveal nested object shapes and mixed array element types in a payload that is difficult to scan directly.
Starting a data-model migration
Create a first-pass TypeScript shape when moving a JSON-consuming script or JavaScript module to TypeScript.
Common mistakes
Mistake:Treating every generated property as known to be required across all real payloads.
Fix:The generator sees only one sample and emits every present property as required. Compare representative payloads or the source schema, then add ? to fields that may be absent.
Mistake:Assuming an array containing one object proves that the input is a single object or that every array item has the same shape.
Fix:Keep the generated array type when the JSON root or property is an array, and test multiple representative elements before trusting the inferred element interface.
Mistake:Removing quotes from numeric, spaced, or punctuated property names after generation.
Fix:Keep the emitted JSON-style quotes. Keys such as "2024" and "display name" do not match the generator's safe identifier pattern.
Mistake:Assuming a reserved word such as class must be renamed or that the generator will quote it.
Fix:Reserved words can be TypeScript property names, and this generator leaves any identifier-shaped key bare. Access or rename it according to your codebase conventions, not because it is a declaration error.
Frequently asked questions
Related guides
Validating JSON Against a Schema: A Practical Guide to JSON Schema
What JSON Schema guarantees, how draft-07 works, and how instance paths identify fields that are missing, malformed, or the wrong type.
How to Convert JSON to TypeScript Interfaces (the Fast Way)
Turn any JSON API response into clean, type-safe TypeScript interfaces in seconds. Learn the rules behind type inference, nested objects, and arrays.
References & standards
Related tools
CHANGELOG Generator
Write a clean, consistent CHANGELOG entry in the Keep a Changelog format from grouped Added, Changed, Deprecated, Removed, Fixed, and Security notes
Chmod Calculator
Calculate Linux file permissions (777, 755 etc) easily.
Credit Card Validator
Validate credit card numbers with the Luhn algorithm and detect the issuing network
Cron Expression Builder
Build and validate cron expressions with visual interface and presets
CSS/JS Minifier
Minify your CSS and JavaScript code to reduce file size.
Database Connection String Builder
Build and URL-encode connection strings for PostgreSQL, MySQL, MongoDB, Redis and SQLite from a simple form — with JDBC and key/value variants