Generating TypeScript Types from JSON Without Missing Optional Fields
Most JSON-to-TypeScript tools infer structure from a single array element, mistyping optional fields. Correct conversion merges keys across every sample.
Many free JSON-to-TypeScript converters infer structure only from the first element of an array, which means fields missing in some records (like an SSO user without an email) get marked as required instead of optional. The generated type compiles but is wrong, and the mistake only surfaces later as a runtime undefined where TypeScript promised a string.
The correct fix is to merge the union of keys across every array element: a field absent in some records becomes key?: T, and a field with differing types across records becomes a union type. This merging logic has to be applied recursively for nested arrays of objects too, so that optionality discovered one level down survives being merged again at the outer level. Identical nested shapes appearing under different property names (like billingAddress and shippingAddress) should also be deduplicated into a single named interface rather than duplicated.
Beyond that, correctness details like inferring empty arrays as unknown[] instead of any[], auto-quoting invalid identifier keys, and explicitly handling null rather than silently dropping it separate a trustworthy converter from one that merely looks right. Skojio's JSON to TypeScript Converter is built specifically around this multi-sample merging approach, running entirely client-side with no data sent anywhere.