Turn a JSON sample into editable source
ToolMint's JSON to TypeScript / Zod Generator infers TypeScript type aliases or Zod schema source from pasted JSON. It supports objects, arrays, strings, numbers, booleans and null at the root. Generation is free, needs no account and runs locally in your browser.
Use it to start an API response type, document a sample payload or prepare runtime validation code. It does not discover the full API contract: values absent from your sample cannot be inferred. Review the output and test it in your project before using it to accept external data.
How to generate types or schemas
- Paste a representative JSON sample, without comments or trailing commas.
- Enter a root name such as
ApiResponse. Use an ASCII identifier starting with a letter, underscore or dollar sign; reserved and imported names are rejected. - Choose TypeScript or Zod and select Generate.
- Review errors, empty-array warnings and inferred properties.
- Copy the source or download the same content as a
.tsfile.
Editing the JSON, root name or mode clears the previous result and disables exports. Reset clears the inputs, notices and output and restores TypeScript mode. Nothing is restored from persistent storage.
What the two outputs mean
TypeScript output describes compile-time types. It does not validate data at runtime. Zod output defines runtime schemas and exports their inferred TypeScript type. It imports zod/v4, uses z.looseObject for open objects, and requires compatible Zod tooling in your project. The generator itself does not load Zod or TypeScript to produce text.
The verification target is the Zod 4 entry point bundled in zod 3.25.67, checked with TypeScript 5.9.3 in strict mode. This is a compatibility target, not a claim that these are the latest releases. Review your own dependency versions before integrating source.
Optional is not the same as nullable
Select Load optional and nullable example, choose TypeScript, then select Generate. The button replaces your JSON and root name. It loads this sample with Rows as the root name:
[{"id":1,"note":null},{"id":2,"note":"ready","active":true}]
The generated TypeScript is:
export type Rows = {
"active"?: boolean;
"id": number;
"note": (null | string);
[key: string]: unknown;
}[];
active is optional because one object lacks that key. note is required because both objects contain it, but its value may be null. The generator examines every array element within the limits, not just the first element. Object keys are sorted so equivalent shapes produce stable source.
Both output modes allow additional unknown object properties. A generated Zod schema preserves these additional keys instead of stripping them. An empty object becomes Record<string, unknown> in TypeScript or z.looseObject({}) in Zod. Open objects are a deliberate starting point; tighten them yourself only when the real contract supports that choice.
Check the same sample in Zod mode
Keep the sample loaded, choose Zod and select Generate again. The missing active property becomes an optional boolean schema. The always-present note property accepts either null or a string; it does not become optional merely because one value is null.
Review this distinction against the actual API contract. Two example rows do not establish whether another response may omit note. Include representative samples or edit the generated schema deliberately. If a JSON Schema contract already defines the allowed values, use the JSON Schema Validator to test it instead of inferring a new contract.
Mixed and empty arrays
An array such as [1,"ready",null] becomes (null | number | string)[]. Unions are deduplicated and ordered deterministically. Nested object samples are merged recursively, and nested types remain inline rather than receiving invented names.
An empty array contributes no evidence about element types. For [[],[1]], the inferred TypeScript type is number[][]. A standalone [] produces unknown[] or z.array(z.unknown()) and a warning. Add representative elements or refine that type manually; the tool will not invent them.
Strings remain strings, even when they resemble dates, URLs or email addresses. Numbers remain numbers rather than integer or range constraints. The generator does not infer enums, defaults, coercion, business rules or validation claims from sample values.
Numeric precision policy
JavaScript numbers have finite range and precision. The parser checks the original numeric text before information can be lost. It rejects overflow, nonzero values that underflow to zero, unsafe integer values and decimal tokens whose normalized decimal information differs from the parsed number's shortest decimal representation.
Routine values such as 0.1, 1.25e2 and 1.00 are accepted. Their ordinary binary floating-point representation is not itself grounds for rejection. Values such as 9007199254740993, 1e309, 1e-400 and 0.10000000000000001 are rejected. Use JSON strings for exact large identifiers, high-precision decimal amounts or other values that must retain their exact representation. This policy is intentionally conservative and is not arbitrary-precision arithmetic.
Keys, safety and limits
Duplicate decoded keys are rejected within each object, including differently escaped spellings of the same key. constructor and prototype are preserved. The decoded key __proto__ is rejected at every depth in both modes because the target Zod parser does not reliably preserve it. Rename or remove that property deliberately; generation never silently drops it.
Property names are quoted and escaped, including quotes, backslashes, newlines, Unicode and HTML-sensitive characters. Input and output are rendered as text, not executable HTML. The tool never executes generated code.
| Limit | Maximum |
|---|---|
| JSON input | 256 KiB measured as UTF-8 bytes |
| Nesting | Depth 40, counting the root as depth 0 and each child value one level deeper |
| JSON values | 20,000, including container values |
| Object properties | 10,000 across the sample |
| Union alternatives | Eight per position; merged JSON kinds normally need fewer |
| Generated source | 512 KiB UTF-8 |
Excessive input is rejected, not sampled or truncated. A sample that fits the input limit can still exceed the output limit when many long property names need escaping. Reduce the shape or work on a smaller representative section.
Privacy and review workflow
JSON, root names and generated source stay in memory in the current tab. The tool does not upload them, store them, add them to URLs or include them in analytics. Its interactive region is masked for Clarity. Copy writes source to the system clipboard only after an explicit action; download creates a local file only after an explicit action. Your operating system or clipboard manager may retain copied content.
Review the sample with the JSON Formatter when syntax or indentation makes it hard to inspect. Use the JSON Schema Validator when you already have a JSON Schema contract and want to validate data against it; this generator does not emit JSON Schema. Extract a representative nested section with the JSONPath Tester. If your actual contract calls for pattern constraints, explore them separately with the Regex Tester before adding them manually.
These tasks are complementary: formatting changes presentation, JSON Schema checks an existing contract, JSONPath selects data, and this tool infers source from samples. Browse the Developer tools for related local workflows.
Technical references
The TypeScript object types documentation explains optional properties and index signatures. The Zod schema API documentation describes objects, unions, arrays and optional schemas. Neither static typing nor a generated sample schema proves that an application has a complete validation policy.