Toolvore

JSON to Zod

Infer a Zod 4 schema from JSON examples, review optional fields and numeric limits, then copy or download complete TypeScript locally.

This tool processes its input contents in your browser instead of sending them to a processing service. Page, asset and fixed usage-measurement requests are described on the Privacy page.

Infer a Zod 4 schema from JSON examples, review optional fields and numeric limits, then copy or download complete TypeScript locally.

How to use it

  1. 1Paste or open a supported local source file, or load the example.
  2. 2Review settings and run the explicit generation or inspection action.
  3. 3Inspect the complete result and download it with its count report.

Example

Input
[{"id":1,"note":"Paid"},{"id":2}]
Output
z.array(z.strictObject({ ["id"]: z.number().int(), ["note"]: z.string().optional(), }))

The second observed object has no note field, so the inferred schema makes note optional. A different future field is rejected by the strict object until you deliberately update the schema.

What happens to your data

JSON samples are parsed in this tab to infer a schema. No sample upload or saved source history is added. Optional measurements exclude source keys, values and generated code.

Last updated November 2026

Paste a JSON response or a small set of example records and generate a readable Zod 4 schema. The tool uses the structure actually present in your sample, keeps the inferred TypeScript type beside the schema and explains the choices that need your judgment.

How it works

The shared JSON lexer reads number spellings and decoded keys before inference. It rejects repeated decoded object keys, unsupported size/depth and invalid Unicode. Strings become z.string(), booleans become z.boolean(), null becomes z.null(), and finite numeric examples become z.number() or z.number().int(). It does not invent email rules, date formats, min/max ranges or enumerations from a single observed string. Those are domain requirements you add after reviewing your actual API contract.

Arrays combine the examples they contain. Object examples are merged by property name. A property seen in some object examples becomes optional when another observed object omits it. A null sample adds a null union, which is distinct from observing an absent property. Mixed scalar kinds become explicit unions. Empty arrays use z.unknown() because an empty sample provides no evidence about future items. Empty objects generate a strict object with no observed properties. Every generated object uses z.strictObject, so unobserved fields fail validation until you deliberately broaden the schema.

Generated property names use computed string keys. Keys such as __proto__, constructor, punctuation and Unicode remain source data instead of being interpreted as prototype setup or executable code. The download includes an import from zod and a z.infer type alias. Install the compatible Zod 4 dependency in your own project before compiling it. The generated module is an artifact for your review. This page does not execute supplied source or install code into your application.

JavaScript number validation has a precision boundary. Unsafe integer samples, nonfinite numeric conversion and nonzero underflow are rejected. Quote an exact large identifier if your contract represents it as text. Decimal validation still uses approximate JavaScript arithmetic. Inferring a number shape does not preserve arbitrary decimal precision or prove that every possible input is valid for your business.

Input is strict UTF-8 JSON up to 128 KiB, 24 nesting levels and 20,000 parser tokens. Repeated decoded keys fail even when their escape spellings differ. Number tokens are limited to 4,096 characters. Each inferred object shape can contain up to 256 distinct fields. Complete generated output is capped at 512 KiB. A failed limit check leaves the source available for revision and offers no partial completed download. The result preview may be shortened, while Copy and Download contain the complete result. Editing the input or settings clears older exports. The root name starts with an uppercase ASCII letter and contains up to 64 letters/digits, excluding Self.

Reading, parsing and generation run in this browser tab. Source text and generated files are held in memory, with no source upload or saved history. Optional workflow measurement records fixed counts and outcomes without JSON keys, link destinations or source values. The separate MCP operation processes explicitly supplied arguments on Toolvore's server under its published smaller limits.

Worked example: Infer an optional field from two records

Input
[{"id":1,"note":"Paid"},{"id":2}]
Result
z.array(z.strictObject({ ["id"]: z.number().int(), ["note"]: z.string().optional(), }))

The second observed object has no note field, so the inferred schema makes note optional. A different future field is rejected by the strict object until you deliberately update the schema.

Common use cases

  • Create a reviewed starting validator for an API response.
  • Compare which fields appear across several JSON example records.
  • Keep a runtime schema and its inferred TypeScript type together.
  • Find numeric samples that cannot safely become JavaScript integer values.

Frequently asked questions

Does a sample prove which fields are optional?+

It gives evidence only from the objects you supply. A field absent in another observed object becomes optional. Review future cases and the authoritative API contract before using the schema.

Does it generate Zod 3 or Zod 4?+

It generates Zod 4 code using z.strictObject, z.union and z.infer. Use a compatible Zod dependency and compile the result inside your project.

Will it turn a date-looking string into a date?+

Strings remain strings. Date, email, enum and range requirements need explicit domain decisions after generation.

Why is a large numeric ID rejected?+

An integer beyond JavaScript's safe integer range can change value when parsed. Quote an exact ID or use a representation that supports the original integer.