Skip to content
cosmodev ~/tools/json-to-zod

JSON σε Zod Schema

Converters & Formatters

Δημιουργήστε schemas επαλήθευσης Zod από JSON. Συμπεραίνει z.string, z.number, z.boolean, z.object, z.array, z.null και z.union για μικτούς πίνακες.

(Τεκμηρίωση στα αγγλικά)

What it does

Generate a Zod validation schema from JSON. Scalars map to their validator (z.string, z.number, z.boolean, z.null), objects recurse into inline z.object({...}), arrays become z.array(...) — and a mixed-type array becomes z.union([...]) of each distinct element type. Drop the output straight into a TypeScript project that uses Zod for runtime validation: API responses, config files, form payloads, fixtures. 100% client-side.

How to use it

  1. Paste JSON into the JSON box (a sample is prefilled — Sample restores it, Clear empties it).
  2. Optionally set a Root name (defaults to Root, used for the const Root = ... binding).
  3. The schema renders live on the right, pinned while you scroll the input.
  4. Copy it, or Download it as schema.ts.

Examples

A flat object — {"id":1,"name":"Ada","active":true,"tags":["a","b"]} →

const Root = z.object({
  id: z.number(),
  name: z.string(),
  active: z.boolean(),
  tags: z.array(z.string()),
});

Nested objects recurse inline — {"user":{"name":"Ada"}} →

const Root = z.object({
  user: z.object({
    name: z.string(),
  }),
});

Mixed arrays become array-of-union — {"xs":[1,"a"]} →

const Root = z.object({
  xs: z.array(z.union([
    z.number(),
    z.string(),
  ])),
});

Edge cases — empty arrays become z.array(z.unknown()); null maps to z.null(); anything the parser rejects shows in the error box instead of the schema.

Good to know

  • Private: parsing is local — safe for sensitive payloads.
  • The generated schema is a starting point: add .min()/.max() refinements where your real data has constraints the sample didn’t show.
  • Related tools: JSON to TypeScript, JSON Validator.
Πηγαίος κώδικας14 γλώσσες

100% client-side · τα δεδομένα σου δεν φεύγουν ποτέ από τον browser. Σου φάνηκε χρήσιμο; Μοιράσου το με έναν συναδέλφο.