Skip to content

JSON to Zod schema converter

Paste a JSON sample. A Zod schema and its type are written beside it.

The schema is as strict as the sample. Loosen it where real data varies, such as a string field that can also be empty.

Ctrl+Enter or ⌘+Enter runs this tool immediately.

Indent
JSON sample
Zod schema

Waiting for input.

Parsing stays in this browser. Input is not uploaded or saved.

How to use this tool

  1. Paste a JSON response, request body, or form payload, or load the sample.
  2. Read the schemas. Each nested object gets its own named schema, followed by a type made with z.infer.
  3. Copy the file, then add refinements such as .email() or .min(1) that a sample cannot show.

Supported formats and limitations

  • Whole numbers become z.number().int(). If the field can hold decimals, remove .int().
  • Strings become z.string(). Formats such as email, URL, or date are not detected.
  • A key missing from some array items becomes .optional(). A value that is null in some items becomes .nullable().
  • A field that is only null becomes z.null(). Replace it with the real type and .nullable().
  • An empty array becomes z.array(z.unknown()).

Examples

An optional key

trusted appears in one session, so it becomes trusted: z.boolean().optional().

{"sessions": [{"device": "a"}, {"device": "b", "trusted": true}]}

A nullable value

An array of numbers and null becomes z.array(z.number().int().nullable()).

{"scores": [3, null, 5]}

Common errors and solutions

Expected double-quoted property name
The sample is not strict JSON. Remove trailing commas and comments first.

FAQ

Which Zod version does this target?
The output uses z.object, z.array, z.union, .optional(), .nullable(), and z.infer, which work the same in Zod 3 and Zod 4.
Why is each schema followed by a type?
z.infer gives you the TypeScript type from the schema, so the validator and the type cannot drift apart.
Is the JSON uploaded?
No. The schema is generated in your browser.

Related tools

  • JSON to TypeScript converter

    Generate TypeScript interfaces from a JSON sample in the browser. Array items are merged, and keys missing from some items become optional.

  • JSON Schema generator

    Generate a draft 2020-12 JSON Schema from a JSON sample in the browser. Types, nested objects, array items, and required keys are inferred.

  • JSON Schema validator

    Check a JSON document against a JSON Schema in the browser. Draft-07 and 2020-12 are supported, and remote $ref values are not fetched.