0

JSON to TypeScript Converter

Convert JSON into TypeScript interfaces, type aliases or a Zod schema live, with real optional-field detection across arrays.

Processing... 0%

Result

Writing TypeScript interfaces by hand for a JSON API response is slow and error-prone: nested objects need their own interface, arrays need an element type, and a field that is sometimes missing needs to be marked optional — miss any of that and the compiler stays quiet while your code drifts out of sync with the real data shape.

This converter does that work for you. Paste any JSON object or array, and it walks the structure recursively: a nested object becomes its own named interface, an array of objects gets an element interface with fields compared across every item in that array — a field present in only some of them is marked with a trailing ?, and a field that is sometimes null and sometimes a value comes out as a proper string | null union instead of one or the other.

A format toggle switches only how the same inferred structure is printed: an interface block, a type alias, or a Zod schema built from z.object(), z.array() and z.union() calls with .optional() and .nullable() where they apply. Zod itself is a separate npm package (npm install zod) — this tool only writes the schema source, it does not install anything for you.

Everything runs locally in your browser the moment you type or paste, with no submit button and no upload — handy for payloads containing real customer data. For working with the JSON text itself rather than its inferred types, see the JSON formatter to pretty-print or minify it and the JSON validator to pinpoint a syntax error before you convert.