{"inline_business":{"json-to-typescript-converter":{"json_input":"JSON to convert","root_name":"Root interface name","use_type_alias":"type instead of interface","add_export":"Add export","readonly_properties":"Readonly properties","copy_code":"Copy","invalid_json":"Invalid JSON: check commas, quotes and braces.","invalid_json_at":"Invalid JSON at line {{line}}, column {{column}}.","empty_input":"Paste JSON in the left box to generate the types."}},"docs_business":{"tools":{"json-to-typescript-converter":{"content":{"title":"Converting JSON to TypeScript types","intro":"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 (?).","details":"

Rules applied

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)

"},"faqs":[{"question":"How do I convert JSON to a TypeScript interface?","answer":"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."},{"question":"How does TypeScript handle a field present in only some objects?","answer":"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."},{"question":"Should I use interface or type for JSON data?","answer":"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."}]}}}}