JSON → TypeScript
Turn any JSON sample into TypeScript interfaces — handles nested objects, arrays of varying shape, and optional fields.
TypeScript
interface Specs {
weight_g: number;
battery_hours: number;
}
interface Review {
user: string;
stars: number;
comment?: string;
}
interface Root {
id: number;
name: string;
active: boolean;
tags: string[];
specs: Specs;
reviews: Review[];
discontinued: null;
}🔒 Type inference runs entirely in your browser.
How inference works
- Objects become named interfaces, lifted out and named after the field they came from (so a
userfield yields aUserinterface). - Arrays of objects are merged into a single shape — fields missing from any element become optional.
- Arrays of mixed primitives become a union (
(string | number)[]). - Empty arrays become
unknown[];nullvalues widen the field type with| null.
Always sanity-check the output for very dynamic JSON — a single sample can't reveal every possibility.
You might also like
- JSON Schema → TypeScriptEmit TypeScript types from a JSON Schema — enum/oneOf/allOf/$ref/definitions all handled.
- CSV ↔ JSON ConverterConvert CSV to JSON or JSON to CSV with quoted fields and configurable delimiters.
- JSON → Struct / ClassGenerate typed declarations from JSON in TypeScript, Python @dataclass, PHP class, Ruby Struct, Go struct, Rust serde, and Java POJO.
- JSON Sample → Zod SchemaGenerate a z.object({...}) schema with inferred TypeScript type from any JSON sample. Detects UUID/email/URL/date formats.