Find optional fields across records
In multiple-sample mode, [{"id":1,"name":"Ada"},{"id":2}] produces an optional name property because one record omits it. In one-document mode, the same input produces an array type.
Turn representative JSON data into a starting TypeScript type. Combine several samples to reveal fields that can be missing, values that can be null, and different element types within arrays.
Types describe the supplied samples, not every valid API response. Review optional fields and runtime validation separately.
Object shapes merge across samples and array items. Missing properties become optional; explicit null remains null in a union. Input is processed in your browser.
Sample data is parsed and inferred locally in your browser without an API request.
Paste one JSON document, or choose multiple-sample mode and provide a top-level array containing examples of the same value.
Choose a valid root type name. Select a root interface or a type alias, and enable readonly output if useful.
Review the inferred properties and warnings. Copy the declarations or download them as a .ts file.
In multiple-sample mode, [{"id":1,"name":"Ada"},{"id":2}] produces an optional name property because one record omits it. In one-document mode, the same input produces an array type.
Samples containing {"contact":{"email":"ada@example.com"}} and {"contact":null} produce an object-or-null union. A field is optional only when an object sample omits it.
An array containing {"x":1} and {"y":true} yields an item shape with optional x and y properties. A mixed array such as [1,"two"] yields Array<string | number>.
Strings, numbers, booleans, and null become their corresponding TypeScript types. Nested object shapes merge recursively. Arrays use the union of observed item types rather than fixed-length tuples. An empty array uses unknown until a populated sample supplies more evidence.
A root object can be declared as an interface. Primitive values, arrays, unions, and empty objects use type aliases. The readonly option marks known object properties readonly and generates ReadonlyArray for arrays. These declarations do not freeze values at runtime.
Sample inference cannot discover every possible response. Add examples with absent fields, empty collections, nulls, and alternate shapes. Dates remain strings, and object samples are merged into broad shapes rather than inferred as discriminated unions. Add runtime validation separately if incoming data is untrusted.
At least one object sample at that level omitted the property. Null is a present value, so it adds null to the type rather than making the property optional.
No. TypeScript declarations describe values for static checking. They do not validate a fetched response or transform data at runtime.
JSON numeric values infer as number. The parser preserves their digits while reading samples, but JavaScript number values can lose large-integer precision. Use string identifiers in your actual data contract when precision matters.
Yes. Every property name is emitted as a quoted TypeScript property. The root type name must be a nonreserved ASCII identifier.