Inference is guessing structure from a sample
The tool walks keys and values, mapping numbers to number, strings to string, booleans to boolean, arrays to merged element types and objects to nested interfaces. The merge step matters: a mixed array yields a union, and objects missing a key in some elements become optional when that toggle is on. Closer samples give tighter types; a single minimal example gives something too permissive to be useful.
Steps
- Paste a representative payload, including the most complex array element.
- Set the root type name, indent of 2 or 4, and whether to emit export.
- Tick missing-field-as-optional to append question marks.
- Choose field naming — preserved, camel, Pascal, snake — and an output target among TS interface, type alias, zod schema, Go struct, Python dataclass and Rust serde.
- Generate, then copy all or download the .ts file.
Interface versus type alias
Interfaces merge, so same-named declarations stack, which suits extensible domain models. Type aliases express unions, intersections and conditional types, better for composite shapes. Nested objects need names either way, otherwise the output becomes one unreadable inline blob; the tool derives names from parent plus key but allows renaming. Field names containing hyphens or spaces must be quoted or the syntax fails.
Three things the sample misses
Number precision comes first: JSON numbers are IEEE doubles in JavaScript, so integers beyond about nine quadrillion lose precision, and big IDs may be sent as strings. Second, null is not absence — a null value means the key exists without content and should type as T | null, while a missing key is what optionality describes. Third, dates are strings; JSON has no date type, so the generated string type needs a comment stating the ISO format.
Common problems
Tiny samples under-typing real payloads. Empty arrays inferring never or unknown and needing hand-written elements. Marking everything optional so callers drown in null checks and the type loses meaning. Conflicting same-named fields across objects merging silently until runtime. And trusting compilation as validation when data still needs a runtime check.
When not to rely on generation:When a contract already exists — OpenAPI, Protobuf, JSON Schema — that is the source of truth and generation is a convenience. Schemas that evolve want hand-maintained types expressing intent rather than a snapshot. Strict runtime validation calls for zod-style libraries that emit types and validators together. Across languages, null semantics diverge enough that generated Go structs and Rust structs need a human look at pointers and Option.