JSON to TypeScript type generator
Generate TypeScript types from JSON objects or arrays. Properties missing from some array examples are marked optional, and the input stays in this browser.
JSON is processed by a worker in this tab and is not sent to the URL, browser storage, or analytics. The result is a static type for the observed examples, not runtime validation code.
Generated TypeScript type
Example JSON is ready. Generate a type now or edit the input.
Conversion example and inference limits
In the sample array, id becomes number and roles becomes string[] because both objects contain them. email, present only in the first object, and active, present only in the second, become optional properties. The tool does not guess about fields absent from every sample.
Frequently asked questions
How are optional properties inferred?
The tool compares object examples in the same array and adds ? only to properties that are absent from some objects. A single object or nested object outside an array keeps its observed keys required. It cannot infer fields missing from API responses that were not provided.
How are empty arrays and objects represented?
An empty array becomes Array<unknown>, and an object with no keys becomes Record<string, unknown>. The tool does not guess types or keys from empty examples.
Does the generated type validate JSON at runtime?
No. The output is a static TypeScript declaration; it does not validate JSON at runtime. Use a separate validator, such as a JSON Schema validator, to check untrusted input at runtime.
Is pasted JSON sent or stored?
No. The input is processed in a browser worker and is not placed in the URL, storage, or analytics events. Copying generated code is an action you choose.
Calculation criteria and reference materials
- IETF RFC 8259 — JSON Data Format
Reference for standard JSON string, object, array, and number syntax. Mapping JSON examples to TypeScript structures is this tool's inference behavior.
- TypeScript Handbook — Object Types
Reference for TypeScript object properties, optional properties, and index signatures. Generated types do not guarantee the presence of API fields absent from the examples.
Verification of calculation criteria: · Calculation·verification principles · Report errors