Toolser

JSON to Zod

Paste JSON to generate a nested Zod schema and an inferred TypeScript type.

Zod schema

import { z } from "zod";

const schema = z.object({
  "name": z.string(),
  "active": z.boolean(),
  "scores": z.array(z.union([z.number().int(), z.number()])),
});

TypeScript type

type Input = {
  "name": string;
  "active": boolean;
  "scores": (number)[];
};
Ad Space Placeholder

How to use

  1. Paste a valid JSON object or value.
  2. Review nested objects, arrays, unions, and null handling.
  3. Copy the generated Zod schema or TypeScript type.

About this tool

JSON is excellent for moving data between systems, but application code still needs a clear contract. This converter reads a JSON example and produces a Zod schema plus an inferred TypeScript type that you can use as a starting point in a project. It recursively understands objects, strings, numbers, booleans, null, nested arrays, and combinations of those values. Empty arrays become z.array(z.unknown()) because an example with no elements cannot reveal its future element type. When an array contains multiple shapes, the generated schema uses a union, preserving the fact that the sample is heterogeneous rather than silently choosing the first item. Integer numbers receive an int refinement; decimal numbers remain regular Zod numbers. Object keys are quoted safely in generated code, so spaces and punctuation in external JSON do not break the result. Invalid JSON is reported in the selected language without attempting a partial transformation. The output is deliberately an inferred baseline: real APIs often need optional fields, defaults, coercion, formats, and refinements that a single example cannot prove. Review and name the schema before production use, especially when an API may omit a property. The entire operation runs in the browser, which makes the page useful for fixtures and payloads that should not be uploaded to a third party.

Frequently asked questions

Related tools