Development & CodeLive๐Ÿ”’ Private

JSON to TypeScript

Convert JSON to TypeScript interface types. Free online JSON to TypeScript converter. No signup, 100% private, browser-based.

How it works

The JSON to TypeScript Converter generates TypeScript interface or type definitions directly from a JSON object or array, inferring field names and types automatically so you don't have to hand-write them.

When working with an API response, a config file, or any external data source, writing accurate TypeScript types by hand is tedious and error-prone โ€” it's easy to miss an optional field or get a nested type wrong. This tool parses your JSON sample and produces matching "interface" (or "type") declarations with correctly inferred primitive types (string, number, boolean), array types, nested object interfaces, and "| null" unions where a value is null.

How to use it: paste a JSON object or array โ€” ideally a representative real-world example, since the types are inferred from the values present. Set the root interface name (defaults to a generic name like "RootObject" if left blank). Choose between "interface" syntax and "type" syntax depending on your project's conventions. Nested objects automatically become their own named interfaces rather than inline anonymous types, keeping the output readable.

Limitations to know: because types are inferred from a single sample, fields that are sometimes a string and sometimes a number in different API responses will only reflect whichever type appeared in your sample โ€” review the output against your actual API documentation for fields you know vary. Arrays of mixed types use the first element to infer the array's type.

Privacy: the conversion is done entirely in your browser using a JSON-to-TypeScript inference algorithm running in JavaScript. Your data โ€” including any real API payloads you paste in โ€” never leaves your device.

Frequently Asked Questions

Does it handle nested objects and arrays?
Yes. Nested objects are converted into their own named interfaces rather than inline anonymous types, and arrays are typed based on their first element, including arrays of objects.
Can I generate 'type' aliases instead of 'interface' declarations?
Yes. A toggle lets you switch between TypeScript 'interface' syntax and 'type' alias syntax, depending on your project's style conventions.
What happens with a field that is sometimes null?
If a value in your sample JSON is null, the generated type includes a '| null' union so the field is explicitly typed as nullable rather than silently defaulting to 'any'.
Is the inferred type always 100% accurate?
Types are inferred from the single JSON sample you provide, so a field that varies in type across different real API responses will only reflect the type seen in your sample โ€” review fields you know are inconsistent against your API docs.