JSON to TypeScript Interface Converter (Online)
Paste JSON and get TypeScript interfaces: nested objects, arrays, null, optional fields, readonly and export options, all generated in your browser.
Converting JSON to TypeScript types
To convert JSON to a TypeScript type, each value maps to its type (string, number, boolean, null), each nested object becomes an interface named after its key, and each array becomes T[]. A field missing from some elements of an array of objects is declared optional (?).
Rules applied
- Arrays: union of the element types, for example (number | string)[]; an empty array gives unknown[].
- null: added as a union (string | null).
- Keys: a key that is not a valid identifier (user-name) is quoted.
- Objects in an array: merged into a single interface; fields missing from some elements become optional.
- Options: interface or type, export, readonly properties.
Example
For [{"a":1,"b":null},{"a":"x"}] you get RootItem[] with a: number | string and b?: null.
Limits
A single sample does not reveal every case: a field always filled in the sample may be null elsewhere. Dates stay strings and integers and decimals are all number. Review the output before using it.
Sources and dates: the JSON format is defined by RFC 8259 (December 2017, which replaces RFC 7159) and by the ECMA-404 standard; a JSON text can be any value, not only an object or an array. The generated code uses the unknown type, available from TypeScript 3.0 (2018, from memory, not rechecked), as well as the optional (?) and readonly modifiers (checked on 14/10/2026)
Frequently Asked Questions
How do I convert JSON to a TypeScript interface?
Paste the JSON into the tool: each object becomes an interface, each array a T[], and null is added as a union. Then copy the result into a .ts file.
How does TypeScript handle a field present in only some objects?
If a key is missing from at least one object in an array, it is declared optional with a question mark (coupon?: string). The field can then be undefined.
Should I use interface or type for JSON data?
Both describe a JSON object well. interface can be merged and extended with extends; type also supports unions. For API data, interface is the most common choice.
Is this tool really free?
Yes, all tools on Kristools are 100% free and accessible without registration.
Is my data protected?
Yes. All processing is performed directly and securely inside your browser. No personal data is sent to our servers.