JSON to TypeScript Converter
Paste a JSON value and get clean TypeScript interfaces or type aliases in one pass — nested objects extracted into named types, array elements merged, null and missing keys turned into optional or nullable members. Runs entirely in your browser; nothing is uploaded.
How it works
This is a deterministic source-to-source transformation, not a guess. The JSON is parsed once with JSON.parse following RFC 8259, which defines the six JSON value types — object, array, string, number, boolean, and null. A single recursive pass then infers a TypeScript type for every node, using the rules from the TypeScript Handbook.
- Primitives. JSON
string→string, number →number(TypeScript has no int/float split, so every JSON number isnumber),true/false→boolean, andnull→null. - Objects become named types. Each object is emitted as an interface (or a
typealias). The name is the parent name plus the PascalCased key — acustomerobject underRootbecomesRootCustomer— so nested types never collide. - Arrays become element types. Under the Union strategy every element is inferred and the results are merged: object fields are unioned, and a key present in only some elements is marked optional. An empty array has nothing to infer from, so it becomes
unknown[]— neverany[]. The First-element strategy instead infers from index 0 only, which is faster for lists you know are uniform. - Optional and nullable. A key whose value is null is handled by your Null handling setting:
key?: T(optional),key: T | null(nullable), orkey?: T | null(both). Keys missing from some merged siblings are always optional, per the Handbook's optional-property rule. - Dedup, ordering, and safety. Structurally identical objects are emitted once and reused. Declarations print children before parents so the file compiles top to bottom. Keys that are not valid identifiers are quoted (
"first-name": string), and reserved root names are rejected before generation.
Because the rules are fixed, identical input and identical settings always produce byte-identical output. As a cross-check, the converter runs a structural assignability test — it confirms your original JSON value satisfies the types it just generated — and shows the result as the Accepts inputbadge. For a shape inferred straight from your value under the Union strategy this is always green; with First-element it may warn that later array elements don't match.
Worked examples
Frequently asked questions
Sources & references
- RFC 8259 — The JavaScript Object Notation (JSON) Data Interchange Format
- TypeScript Handbook — Everyday Types (interfaces, unions, optional properties)
- TypeScript Handbook — Object Types (nested and optional members)
The type-mapping rules on this page were last cross-checked against the RFC 8259 value grammar and the TypeScript Handbook on 2026-06-23. The converter is deterministic, so its output can be reproduced exactly from the same input and settings.
Related tools
Comments & feedback
Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.
Found a JSON shape that converts wrong, or want a feature like JSON Schema input?
Email me at [email protected] — most fixes ship within 24 hours.