json-schema-generator
A JSON Schema generator analyzes a JSON sample and emits a matching JSON Schema document β a formal specification of the data's shape, used for runtime validation, API documentation, and code generation. The ZTools JSON Schema Generator infers types, required vs optional fields (based on which keys appear across multiple samples), enum candidates (when a string field has a small fixed set of observed values), and format hints (date-time, email, uri detected from string content). Output supports JSON Schema Draft 2020-12 (latest), Draft 7 (most widely tooled), and Draft 4 (legacy).
Use casesβ
Generating a schema for runtime validation of API responsesβ
Paste a sample API response, get a JSON Schema, plug into Ajv or zod-from-schema for runtime validation. Catches API breaking changes the moment they hit production rather than at the next downstream consumer.
Building an OpenAPI specification for an existing APIβ
OpenAPI uses JSON Schema for request/response shapes. Generate schemas from sample payloads, paste into your openapi.yaml. Faster than authoring schemas by hand for every endpoint.
Documenting a complex JSON file formatβ
A well-named JSON Schema is the most precise documentation for a JSON file format. Generate from a real example, refine the descriptions, ship as your spec β readable both by humans and by tools.
Code generation: typed clients in any languageβ
JSON Schema is the input format for quicktype (TypeScript, Go, Java, C#, Python, Rust, ...). Generate the schema here, run quicktype to get typed clients in every language your team uses.
How it worksβ
- Paste JSON sample(s) into the input pane β Single object, single array, or multiple objects (best β more samples means better required/optional inference).
- Choose target draft β Draft 2020-12 (latest), Draft 7 (broadest tooling), Draft 4 (legacy compatibility).
- Configure inference options β Detect formats (
date-time,email,urifrom string patterns), generate enum from low-cardinality strings, mark fields as required if present in all samples. - Click Generate β The tool walks the JSON tree, infers a type for every leaf, builds an
objectdefinition for every node withproperties,required, andadditionalProperties: false. - Review and refine β Generated schema appears in the right pane. Add
title,description, andexamplesfields by hand to enrich the spec for documentation use.
Examplesβ
Input: { "id": 1, "name": "Ahsan", "email": "a@b.com" }
Output: { "$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object", "properties": { "id": {"type":"number"}, "name": {"type":"string"}, "email": {"type":"string", "format": "email"} }, "required": ["id","name","email"] }
Input: [{"x":1,"y":2}, {"x":3}]
Output: x required, y optional (only present in first element).
Frequently asked questionsβ
How does the tool decide what fields are required?
A field is marked required if it appears in every sample object. With a single sample, every field is required (provide multiple samples for accurate optionality detection).
What's the difference between JSON Schema drafts?
Draft 4 is legacy (2013); Draft 7 (2018) is the most widely supported by tools (Ajv, OpenAPI 3.0); Draft 2020-12 is current and adds $dynamicRef, unevaluatedProperties, etc. Pick the draft your downstream tool requires.
Can I use the generated schema for validation?
Yes β feed it to Ajv (Node.js / browser), Python jsonschema, Go xeipuuv/gojsonschema, or any other JSON Schema validator. The generated schema is valid against the spec.
Does it handle nested objects and arrays?
Yes β recursively. Nested objects produce nested properties blocks; arrays produce items definitions inferred from element samples.
How are union types handled?
Heterogeneous arrays (e.g., [1, "a", true]) produce items: \{ anyOf: [...] \}. Properties whose values vary in type across samples produce anyOf for that property.
Will the schema catch every runtime issue?
It catches shape and type issues but not semantic constraints (e.g., "this number must be positive", "this string must be β€ 50 chars"). Add those manually after generation.
Tipsβ
- Provide multiple samples for accurate required-vs-optional inference.
- After generation, add
titleanddescriptionto each field β turns the schema into living documentation. - Pair with Ajv for runtime validation in JavaScript/TypeScript projects.
- For the strongest contract, hand-write semantic constraints (min/max, pattern) β generation can't infer those.
Try it nowβ
The full json-schema-generator runs in your browser at https://ztools.zaions.com/json-schema-generator β no signup, no upload, no data leaves your device.
Last updated: 2026-05-05 Β· Author: Ahsan Mahmood Β· Edit this page on GitHub