Generate TypeScript Types from Complete JSON Examples
Infer TypeScript types from complete JSON documents, preserve literal keys and distinguish missing fields from null locally.
Tool workspace
JSON to TypeScript
Exported TypeScript type declarations.
Types describe the examples; they do not validate data at runtime. JavaScript numbers can approximate large integers.
Enable JavaScript to generate code. You can still read and edit JSON.
This browser cannot start the local Worker. Generation is unavailable.
All elements and documents contribute to one contract. An array root stays an array. An absent field differs from null.
Up to 20 documents, 1,000,000 UTF-16 input units and 2,000,000 output units; other resource budgets also apply.
Your JSON is processed locally in a browser Worker. It is not uploaded or stored.
Changing to one document keeps only the active example. Confirm or cancel.
Use 1–64 ASCII letters and digits, beginning with a letter. Reserved names are rejected.
Ready for JSON input.
Some diagnostic details are omitted. Notice totals remain visible.
Name details
Clipboard is unavailable or denied. Download the file or explicitly open the complete code for manual copying. A large file may take longer to display.
One document or several complete examples
Paste strict JSON or load a local UTF-8 file. Choose one document, or add up to twenty complete documents of the same contract. Each example must be valid; empty examples, duplicate decoded keys, comments and concatenated documents stop the operation. Generate code explicitly. All elements contribute, including late array elements. A root array stays an array.
The editor shows the active example and total count. After generating, review the filename, root type expression, JSON node count and size of the complete code. These details describe the current result; copying and downloading include the full file even when the preview is shortened.
[{"id":1},{"id":2,"nombre":"Ana"}]
export type RootItem = {
"id": number;
"nombre"?: string;
};
export type Root = Array<RootItem>;
Presence, null and literal keys
The optional ? means a field was absent from some objects at that location. Null is a separate type: [{"x":null},{"x":"a"},{}] produces an optional null | string field. Requiredness is observed presence, not proof of an API rule. Objects at different properties remain separate contexts. Every JSON key uses a quoted literal, preserving class, __proto__, empty keys, quotes and Unicode. Only code type names are adjusted for collisions.
Mixed arrays keep every branch; [] uses Array<unknown> with a notice. Empty objects use Record<string, unknown> because no fields were observed. No dates, enums, tuples, discriminators, runtime validators or business logic are inferred. Exported type aliases support TypeScript’s strict and exactOptionalPropertyTypes; type declarations do not validate data at runtime.
Numbers, limits and complete exports
Numbers remain number. Original number lexemes supply numeric evidence; JavaScript precision notices remain visible. The destination warns when large integers or precision loss can make number approximate. It never silently changes numbers to strings or bigint.
The compiled profile allows 20 samples, 1,000,000 UTF-16 input units, 4,000,000 UTF-8 input bytes, files of 4,000,000 bytes, depth 200 and 100,000 source nodes in total. Parsing has 1,000,000 shared work units; inference has 100,000 visits, 10,000 types, 20,000 distinct fields and 2,000,000 merge work units. Emission allows 2,000 declarations and 4,000,000 work units. Output allows 2,000,000 UTF-16 units and 8,000,000 bytes. Maxima cannot necessarily be reached together. Generation times out after 15 seconds and publishes no partial code on failure.
The preview is limited to 20,000 UTF-16 units; copy and download include the complete current types.ts, as text/plain;charset=utf-8, UTF-8 without BOM, LF and one final newline. Details show at most 100 diagnostics and 50 name rows totaling 10,000 units, with omitted counts. A denied clipboard offers an explicit full-code manual copy control. One initial BOM is removed for parsing; positions refer to the visible original text. Canceling terminates the Worker and preserves input. Editing any sample, order, mode or root name invalidates output and exports.
Processing stays local in a browser Worker, with no uploads, storage, remote compiler or data in navigation links. JavaScript and local Worker support are required. The tool generates declarations and never compiles or executes them in the page.