deftools.io Developer Tools

JSON → Zod Schema

Generate Zod validation schemas from JSON — z.object(), z.string(), z.number(), z.enum(), z.array() with nullable support. Paste JSON, get runtime type-safe validation code.

About this tool

Writing Zod validation schemas by hand for every API response or config file is repetitive. Paste your JSON here and get the corresponding Zod schema — nested objects become nested z.object() calls, arrays become z.array(), and null values can be marked as .nullable().optional() with one checkbox.

Example: {"id":1,"name":"Alice","address":{"city":"NYC"}} produces a Schema Zod object with id: z.number().int(), name: z.string(), and address: AddressSchema — plus an AddressSchema for the nested object. String arrays with few unique values become z.enum() automatically.

The generated schemas are a starting point — add refinements like .min(), .max(), or .email() once the exact validation rules are known.

FAQ

How are nested objects handled?

A nested object under a key like "address" generates a separate schema named AddressSchema and references it as z.object(AddressSchema) on the parent. The root schema name is configurable via the checkbox and text input above.

When does the tool generate z.enum()?

When an array field contains only strings and has between 1 and 8 unique values, the tool emits z.enum([...]) instead of z.array(z.string()). This covers common cases like roles, statuses, and categories.

What does "Nullable optional" do?

When enabled, any field with a null value in the sample becomes .nullable().optional() — meaning the field can be absent or explicitly null. Without it, null fields are emitted as z.null().

Does it handle arrays of objects?

Yes. If the root is an array of objects, the first element defines the shape and the root becomes z.array(ElementSchema). Nested objects inside array items are also extracted into their own schemas. Empty arrays fall back to z.array(z.any()) since the element type is unknown.

How do I share a JSON snippet?

Click the Share button to copy a deeplink URL with your JSON encoded in the hash. Anyone opening that link will see the same JSON and generated schema automatically (limited to about 3,000 characters of JSON).

What is the import statement for?

The generated code starts with import { z } from "zod" — it assumes you have Zod installed in your project. Remove or adjust the import path if your project uses a different setup.

More developer tools

Copied!