Omnikit
DevFilesMoneyAll tools
Ctrl K
Dev toolsFile toolsMoney calculatorsAll tools
HomeDeveloper toolsJSON to Zod

JSON to Zod

dev

Paste a JSON sample and get a Zod schema with its z.infer type, ready to copy

Runs in your browser. Nothing you type is sent anywhere. Checked against sources on 22 Oct 2026.

Writing a Zod schema by hand for a large API response is slow and easy to get wrong. Paste 1 sample and get the schema back, with nested objects, arrays, optional and nullable fields worked out from the data, and a z.infer type to go with it. The sample never leaves your browser.

Next:
  • JSON Schema Validator Validate JSON against a JSON Schema (2020-12, 2019-09, draft 7), with each error located
  • JSON to TypeScript Generate TypeScript interfaces or types from a JSON sample

How to convert JSON to a Zod schema

1

Paste a sample JSON response into the JSON pane, or click Try an example.

2

Set the Root name and choose Inline for one nested schema or Named for one schema per object.

3

Choose how null values are written, .nullable() or .nullish(), and turn string formats, .int() or .strict() on or off.

4

Click Copy, or the download icon to save a .ts file with the schemas and their z.infer types.

About JSON to Zod

This JSON to Zod converter reads a sample of your data and writes the matching Zod schema, so you can validate what an API, a form or a config file really sends at runtime and get the TypeScript type from the same source. The output updates as you type.

How fields are worked out. Every item of an array is read, not just the first. Objects in an array are merged into one schema, and a key that some items lack gets .optional(). A null value adds .nullable(), or .nullish() if you choose it or if the key is also missing somewhere. A field that holds different kinds of value becomes a z.union([...]). Empty arrays become z.array(z.unknown()) and empty objects z.record(z.string(), z.unknown()), because there is nothing to infer from.

String formats. When every sample of a string field is an email address, an http or https URL, a UUID, an ISO date or an ISO date-time with a Z or +hh:mm offset, the matching check is added: .email(), .url(), .uuid(), .date() or .datetime({ offset: true }). The patterns are the ones Zod itself uses, so a sample that Zod 4 would reject, such as an offset written +0530, stays a plain string. Whole numbers get .int() only if you turn it on.

Inline or named. Inline writes one schema with everything nested inside it. Named writes one constant per object shape, children before their parents so the file runs top to bottom, reuses one schema for identical shapes, and adds a z.infer type for each.

The code uses calls that work in both Zod 3.23 and later and Zod 4. Every case in the tests is run through the real Zod library to check that the schema accepts the sample it came from. Nothing you paste is sent anywhere. Related tools: JSON to TypeScript, JSON Schema Validator, JSON Formatter.

Frequently asked questions

How do I convert JSON to a Zod schema?

Paste the JSON into the left pane and the schema appears on the right as you type. Set the root name, choose Inline or Named, then press Copy or Ctrl+Enter and paste the result into a .ts file that imports z from zod.

Does the generated schema work with Zod 3 and Zod 4?

Yes. The output only uses calls both versions have: z.object, z.array, z.union, z.record with two arguments, .optional(), .nullable(), .nullish(), .strict() and the string checks. Zod 4 marks some string checks as deprecated in favour of z.email() and similar, but they still work.

How are optional and nullable fields detected?

When an array holds several objects, they are merged into one schema. A key that is missing from some of them gets .optional(). A key that is null in some sample gets .nullable(), and a key that is both missing somewhere and null somewhere gets .nullish(), which allows either.

Is my JSON uploaded anywhere?

No. The conversion runs entirely in your browser, so the JSON you paste never leaves your device and no copy reaches a server. API responses with tokens, email addresses or customer details are safe to paste. Closing the tab clears the input.

Why is a field typed as a plain string instead of .email() or .datetime()?

A format check is added only when every sample of that field matches it. One value that is not an email, or a date-time without seconds or with an offset written +0530, keeps the field a plain z.string(), because Zod would reject that value.

What is the difference between Inline and Named?

Inline writes a single schema with every nested object written inside it, which is easy to read for small payloads. Named writes one constant per object shape, such as AddressSchema, so you can reuse and export each part, and identical shapes share one schema.

Sources

  • Zod documentation: Defining schemasz.object, z.array, z.union, .optional(), .nullable(), .nullish(), strict objects, z.iso.datetime offsets
  • Zod 3 documentationz.string().email(), .url(), .uuid(), .datetime() and .date() in Zod 3.23 and later

Last verified 22 October 2026.

Rates and rules change; check the source before you rely on a figure.

Still stuck? Ask about JSON to Zod and anybody who knows can answer. No account needed.

Common uses

  • Zod Schema GeneratorWrite Zod validation schemas from a real API response instead of by hand

Same job, other tools: TSV to JSON – Convert tab-separated values, such as a paste from Excel, into JSON · JSON to YAML – Turn JSON into clean, readable YAML for configs · Query String Parser – Split a URL query string into a table of decoded parameters.

Related tools

All developer tools
Base64 Encode & DecodeText and files to Base64 and back, with URL-safe mode and image previewUnix Timestamp ConverterUnix timestamps to dates and dates to timestamps, in any time zoneJSON to TypeScriptGenerate TypeScript interfaces or types from a JSON sampleCSV to JSONConvert CSV to JSON and JSON to CSV, with a table previewYAML to JSONConvert YAML to JSON and JSON to YAML, with anchors resolvedURL Encoder / DecoderPercent-encode or decode text and URLs, and see every part of a linkColor ConverterHEX, RGB, HSL, HWB, OKLCH and CMYK in both directions, with a contrast checkNumber Base ConverterBinary, octal, decimal, hex and any base to 36, exact at any size, with two's complement
Was this tool helpful?
Omnikit

Small jobs, done in your browser. Free, fast and private. Files are never uploaded.

Files

  • Compress Image
  • Image to PDF
  • Merge PDF
  • Compress PDF
  • PDF to Word
  • Word to PDF

Dev

  • JSON Formatter & Validator
  • Base64 Encode & Decode
  • JWT Decoder, Verifier & Encoder
  • Password Generator
  • UUID Generator
  • Unix Timestamp Converter

Money

  • SIP Calculator
  • EMI Calculator
  • GST Calculator
  • FD Calculator
  • PPF Calculator
  • Lumpsum Calculator
GuidesQuestionsAboutHow we checkLaw library (beta)PrivacyTermsDisclosureContactMore: Exam practice (UGC NET Paper 1)Runs in your browser. Nothing is uploaded. © 2026 Omnikit (theomnikit.com)