JSON to Zod & JSON Schema
Infer Zod validators and JSON Schema from example JSON. Add a short description like a prompt for agents and docs. Free, private.
Example JSON
Output
How to Use
- 1Paste a representative JSON example (or multiple samples / NDJSON).
- 2Name the schema and optionally describe it for agents/docs.
- 3Infer, then copy Zod into TypeScript or JSON Schema into your API tooling.
What gets inferred
Formats
email · uuid · url · datetime from string samplesHeuristic format detection from values.
Nesting
objects, arrays, and optional fields across merged samplesMissing keys in some samples become .optional().
Tips
- •Use realistic examples: inferred schemas follow the samples you provide.
- •Merge multiple samples to capture optional fields correctly.
- •Tighten enums and unions manually when business rules are richer than examples.
- •For OpenAPI operations, prefer OpenAPI to Tool Schemas.
How this inference works
This is deterministic inference, not a model. inferSchemasFromJson parses a JSON document, an array of documents, or NDJSON, and walks each value. It maps strings, numbers, integers, booleans, nulls, objects, and arrays to JSON Schema draft 2020-12, then emits the matching Zod code. String samples get heuristic formats: email, uuid, url, and datetime.
When you provide several samples, the tool merges them. A key missing from one sample becomes .optional(), and a value that changes type becomes z.unknown(). Everything runs in the page, so the payload stays on your device.
A real inference
Input: an order object with a nested customer, an array of items, an integer total, and ISO date strings. The tool produces this Zod output, trimmed to the schema body:
export const OrderSchema = z.object({
"id": z.string(),
"customer": z.object({
"email": z.string().email(),
"name": z.string(),
"marketingOptIn": z.boolean(),
}),
"items": z.array(z.object({
"sku": z.string(),
"quantity": z.number().int(),
"unitPrice": z.number(),
})),
"total": z.number().int(),
"status": z.string(),
"createdAt": z.string().datetime({ offset: true }),
});The same run emitted additionalProperties: false for every object and an empty warnings list. The email and datetime formats came from the values, not from a schema you supplied.
What inference cannot know
- One sample cannot prove that a field is optional or can be null. Add more samples when a field can be absent or null.
- Enums are not inferred. In the example,
statusisz.string(), not a union of paid, pending, and failed. - Formats are pattern heuristics. An opaque order ID that looks like a UUID becomes
uuid, even when your system treats it as a string. - An array that mixes types becomes
z.array(z.unknown()), and no warning appears. Check the output before you ship the schema. additionalProperties: falseis strict. A new field fails validation until you regenerate or edit the schema.- Large payloads run on the main thread, so the page can pause while it infers.
- It does not check business rules, uniqueness, or database constraints.
When to use something else
- When you have an OpenAPI or Swagger file, use OpenAPI to Tool Schemas for operation-level tools.
- To validate or format the JSON first, use JSON Formatter.
- To score the generated tool schema, use the MCP Tool Checker.
Frequently Asked Questions
How does JSON to Zod / JSON Schema work?
Paste one or more example JSON values. Instant Tools infers types, nested objects, arrays, and common string formats (email, uuid, url, datetime), then emits Zod TypeScript and JSON Schema draft 2020-12. Optional description text documents the schema like a short prompt.
Is this an AI prompt-to-schema model?
No LLM call is required. Inference is deterministic and runs in your browser from your examples. Use the description field to note intent for agents and docs.
Can I pass multiple samples?
Yes. Paste an array of objects as separate JSON documents, or NDJSON (one object per line). Samples are merged so optional fields stay optional when missing in some examples.
Does my JSON leave the browser?
No. Parsing and codegen never upload your payload.
When should I use OpenAPI to Tool Schemas instead?
If you already have an OpenAPI/Swagger file, use OpenAPI to Tool Schemas for operation-level agent tools. Use this tool when you only have example JSON payloads.
Why does a field come out as optional?
With multiple samples, a key that is missing from at least one sample becomes optional. A key that is null in one sample becomes nullable. To require an optional field, remove .optional() after you copy the output.
Can it infer enums or unions?
No. A string value becomes z.string(), and a number becomes z.number(), even when the real field only accepts three values. Tighten those by hand with z.enum() or z.union() after you copy the output.
What happens with nulls or mixed arrays?
A null next to another value makes the field nullable. An array that mixes types, such as numbers and strings, becomes z.array(z.unknown()), and no warning appears. Integers mixed with decimals become numbers. Objects in an array merge into one shape, where a key that only some of them have is optional. Check the output before you ship a schema built from mixed data.