JSON → TYPESCRIPT

JSON to TypeScript

JSON to TypeScript infers interfaces and types from sample data. Arrays of objects are considered together so missing fields become optional and mixed values form unions.

Drop a file or paste below
Conversion options

Ready

Optional properties and nullable types

A property missing from some object samples receives ?. A property present with null receives a union containing null. Those are different cases: a missing email may be email?: string, while an explicit null may be email: string | null. Arrays of objects are merged across the samples instead of assuming only the first item represents every record.

Arrays, nested objects and unusual keys

Nested objects receive named interfaces. Mixed arrays use union element types, while empty arrays use unknown[] because no item type is available. Keys containing spaces or hyphens are quoted. Reused names receive distinct suffixes so two unrelated nested structures do not accidentally share one interface definition.

Sample inference and runtime validation

The generated types describe the values present in the sample, not every value a remote API might later return. A date-looking string remains string, and no enum is inferred from a single value. TypeScript declarations do not validate incoming JSON at runtime. Include representative records and review optional fields before adding the types to a project.

Format references

TypeScript everyday types · JSON format

File content is read and converted in the browser. Conversion does not upload the source to a server.

Frequently asked questions

Does it inspect every array object?

Yes. It combines object samples to find missing and mixed-type fields.

Does this validate JSON at runtime?

No. The output is TypeScript declarations, not runtime validation code.