Developer Tools

JSON to TypeScript — Interface & Type Generator

Generate TypeScript interfaces or type aliases from JSON samples in your browser. Handle nested objects, arrays, optional properties and unions, then copy the declarations.

Generate a starting point for TypeScript types from JSON. Limits: 100,000 input characters (UTF-16 code units), depth 64 (root = 0), 10,000 values, 500,000 output characters and 1,000 declarations. This tool does not send your input to a server. Page resources, analytics and ads may use the network.

Type generation settings

Up to 64 ASCII letters, digits, _ or $. No leading digit, reserved word or Record.

Enter JSON to generate types.

The output is a set of type declarations. When export is off, place it in a module that already has an import or export, or add export {} to the file. In a global script, names such as Array or Node may conflict with existing types. Check for other name collisions in the same scope.

How inference works and its limits

Types are inferred from the observed values. A property missing from some objects in an array becomes optional; different observed types form a union. A null-only property stays null, even when made optional. An empty array becomes unknown[]; an empty object by itself becomes Record<string, unknown>.

Small-object inlining applies to child objects with at most two properties. readonly prevents property reassignment; it does not make array elements immutable. Array and primitive roots always use a type alias. Date strings remain string.

Unseen values and business rules cannot be inferred. Generated types do not validate or convert data at runtime, and number does not guarantee numeric precision or range. Formatting is independent of type options and declaration limits; it checks JSON syntax and input/output length while preserving number notation. For duplicate keys in one object, inference uses the last value. Review the types and numeric handling in your project.

About JSON to TypeScript — Interface & Type Generator

Turn a JSON sample into TypeScript declarations

Generate interfaces or type aliases from the values in a JSON sample. The result is a starting point: it cannot infer unseen values or business rules, and it does not validate or convert data at runtime. Review the declarations before using them in your project.

Generation and formatting run in your browser. This tool does not send your input JSON to a server. Page resources, analytics and advertising may still use the network.

Arrays, missing properties and null

Inference examines all array elements. Different observed types become a union, and a property absent from some objects becomes optional. Nested objects are combined in the same way. A property whose only observed value is null stays null. Making null-containing properties optional allows them to be absent; it does not remove null from their type.

Empty arrays become unknown[]. An empty object by itself becomes Record<string, unknown>. Date strings remain string, and numbers become number. A number annotation does not guarantee JavaScript numeric precision or range. If an object has duplicate keys, inference uses the last value.

Formatting is independent of the root type name and declaration limits. It checks JSON syntax and length limits and preserves the original number notation, including large numbers.

Options, limits and using the output

Choose interface or type, export, readonly, optional null-containing properties, and inlining for child objects with at most two properties. Array and primitive roots always use type. readonly prevents property reassignment; it does not make array elements immutable.

The root type name accepts up to 64 ASCII letters, digits, underscores or dollar signs, with no leading digit. Reserved names and Record are rejected. Child type names are adjusted to safe identifiers and numbered to avoid collisions; property names are preserved.

The output is a set of declarations. With export turned off, use it inside a module that already contains an import or export, or add export {} to a standalone file. In a global script, names such as Array and Node may conflict with existing declarations. Check other names in the same scope too.

Limits are 100,000 input UTF-16 code units, nesting depth 64 with the root at zero, 10,000 values, 500,000 output characters and 1,000 declarations. Invalid or over-limit input produces no partial type output. Formatting leaves the input unchanged if the formatted text would exceed the input limit.

Frequently asked questions

Q. How do missing properties differ from null?
A property missing from some array objects receives ?. null remains a value type. The optional-null setting additionally permits that property to be absent.
Q. Can I use large or deeply nested JSON?
Within these limits: 100,000 input UTF-16 code units, depth 64 (root zero), 10,000 values, 500,000 output characters and 1,000 declarations. Split larger inputs into representative samples and review the combined types.
Q. What if copying or pasting does not respond?
After five seconds, the tool shows a waiting message. While a copy is unfinished, avoid other copy operations, including manual copying: the original request may finish late and overwrite the clipboard with older content. Once it settles, retry or copy manually. If pasting does not respond, you can paste into the input field manually. The original API request cannot be cancelled, and the same API operation remains unavailable until it finishes.
Q. Should I choose interface or type?
Both can describe objects. Interfaces support declaration merging; type aliases can also describe unions and primitives. Choose according to your project. Use non-exported output in a module and check for existing type names.
Q. Is my JSON uploaded?
This tool generates types and formats JSON in your browser without sending the input. Page resources, analytics and ads may still make network requests.

Sources and specifications

Related tools

Questions or feedback? Contact NanToo

Rate this tool
—(0 ratings)