JSON to TypeScript / Zod Generator

Infer TypeScript types or Zod schemas from JSON arrays. Try missing versus null fields, inspect optional properties and download editable source locally.

JSON to TypeScript / Zod

Local sample inference

Compare optional and nullable fields

Load two rows with a missing field and an explicit null, then select Generate. This replaces the JSON and root name; your output mode stays selected.

JSON sample

256 KiB UTF-8 maximum. Root depth 0; maximum depth 40.

Output mode

Generated source

No source generated.
Steps

How to use

  1. Paste a representative JSON sample.
  2. Enter a valid root identifier and choose TypeScript or Zod.
  3. Generate and review errors, warnings and inferred source.
  4. Copy or download the source, then test and refine it in your project.
Examples and use cases
  • Generate an API response type from a nested object.
  • Merge array object samples with missing and nullable fields.
  • Generate an open Zod schema for local runtime validation.
Privacy, limits and tool details

Key facts

Input
Any JSON root value, up to 256 KiB UTF-8
Output
TypeScript source or Zod source importing zod/v4; .ts download
Inference
All array elements, merged object shapes, optional missing keys, explicit null unions
Processing
Local browser memory; no input upload or persistent storage
Limits
Depth 40 (root 0), 20,000 values, 10,000 properties, eight union alternatives, 512 KiB source
Main limitation
A sample cannot establish all valid values or business rules
Privacy

Privacy and processing

Processing method: A bounded local parser checks keys and numeric tokens, then one shared inference model emits either source format.

Privacy model: JSON, root names and generated source remain in browser memory and are excluded from analytics and storage.

Limitations

Limitations

  • No inference of enums, dates, integer constraints, email rules or business requirements.
  • Duplicate keys, decoded __proto__ keys and numbers with detectable decimal information loss are rejected.
  • Objects allow additional unknown properties; empty arrays need manual element-type review.

Page freshness

Published
Sep 19, 2026
Last updated
Oct 04, 2026
Features

Benefits

Shared inference

Both output modes use the same deterministic sample model.

Local source generation

Inputs stay in the tab; no compiler or Zod runtime is needed to generate text.

Explicit uncertainty

Empty arrays warn and unknown additional object properties remain allowed.

Tips

Pro tips

  • Include representative array elements, including missing and nullable fields.
  • Keep exact large numeric identifiers as strings.
  • Add domain constraints only after checking the actual API contract.
Watch out

Common mistakes to avoid

  • Treating one sample as proof of every valid response.
  • Confusing an absent property with a property containing null.
  • Expecting date or email strings to produce runtime format constraints.

Sources

Detailed JSON to TypeScript / Zod Generator guide

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

  1. Paste a representative JSON sample, without comments or trailing commas.
  2. 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.
  3. Choose TypeScript or Zod and select Generate.
  4. Review errors, empty-array warnings and inferred properties.
  5. Copy the source or download the same content as a .ts file.

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.

Frequently asked questions

No. It describes the supplied sample, not every valid response. Review required fields, nullability, array contents and business rules before using it.

A key missing from some object samples becomes optional. A present null value adds null to its type without making the key optional.

The output imports zod/v4 and uses the Zod 4 API, including looseObject. Verification uses the zod/v4 entry point bundled in Zod 3.25.67 with TypeScript 5.9.3. Check compatibility with your project.

No. Generation uses browser memory only. JSON, root names and generated source are not sent to analytics or stored by this tool.

The parser rejects duplicate decoded keys, decoded __proto__ keys, numeric overflow, nonzero underflow, unsafe integers and decimal information loss. Preserve exact numeric values as strings when needed.
7 min read Works in browser Privacy notes