JSON Schema Generator
Generate JSON Schema from example JSON data automatically. Create validation schemas for APIs. Free online JSON Schema builder for developers
JSON Schema is the closest thing the JSON world has to a contract — it is what powers OpenAPI request validation, AJV runtime checks, and form-rendering libraries. Hand-writing a schema for an existing response is tedious and error-prone; the fields you forget to mark required are the ones that break in production. This generator infers a JSON Schema (Draft 2020-12 by default, with Draft 7 and Draft 4 as options for older toolchains) from sample data, marks fields required when present in all samples, and emits enum sets for fields whose values cluster on a small list.
Draft versions and why they matter
- Draft 4 — what most OpenAPI 2.0 (Swagger) tools still understand. id keyword, no $id, no const.
- Draft 7 — the most-supported draft in 2026. AJV default, used by OpenAPI 3.0. const, contains, if/then/else.
- Draft 2019-09 / 2020-12 — current state of the art. $ref to subschemas, unevaluatedProperties, $defs replaces definitions. OpenAPI 3.1 aligns with 2020-12.
If your runtime is "old AJV" or "the only validator we have in this codebase from 2019", target Draft 7. If you control the whole stack, use 2020-12. Mixing drafts in one project leads to silently-divergent validation behavior — pick one.
Working example
Input
Sample:
{
"id": 42,
"email": "user@example.com",
"role": "admin",
"tags": ["beta", "internal"],
"metadata": null
}Output
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"id": { "type": "integer" },
"email": { "type": "string", "format": "email" },
"role": { "type": "string" },
"tags": {
"type": "array",
"items": { "type": "string" }
},
"metadata": { "type": ["null", "object"] }
},
"required": ["id", "email", "role", "tags", "metadata"],
"additionalProperties": false
}Notes: 42 is detected as integer (not just number) — narrower constraint. "format": "email" added because the string passes the email regex. metadata is null in this sample but the generator widens to ["null", "object"] so future samples with actual metadata still validate. additionalProperties: false is the conservative default — turn it off if your API may add fields you do not want to fail on.
Things you should hand-tune after generation
- minLength / maxLength — generated as unconstrained string by default. If your DB column is VARCHAR(255), set maxLength: 255 to fail fast.
- pattern — regex for IDs, slugs, account numbers. Generator detects email and UUID by format, but not your custom internal ID format.
- enum — set of allowed values. If "role" only ever takes 4-5 values, "enum": ["admin","user","guest"] is a tighter contract than "type": "string".
- required — generator marks every field present in all samples as required. Loosen for fields that are optional in your contract but always present in samples.
- additionalProperties — true (Postel's law, ignore unknowns) vs false (strict, reject unknowns) is a deliberate API-design decision. Default to false for new APIs you control; true for clients consuming third-party APIs.
When to reach for this tool
- You are documenting an existing API in OpenAPI 3 and need request/response schemas. Paste an actual response, refine the inferred schema.
- You are adding runtime validation to an Express endpoint with AJV and need a starting schema for the request body.
- You inherited a REST API with no schemas and want to generate them retroactively from logged production responses (after stripping PII).
- You are designing a JSON contract between two services and want a strict schema for the producer to validate against before publishing.
What this tool will not do
- It will not infer business rules. "balance must be ≥ 0" or "endDate must be after startDate" are constraints the data cannot tell the generator. Add manually.
- It will not infer all formats. Email and UUID are detected; IPv4 addresses, ISO 8601 dates, and URI patterns may need manual format keywords.
- It will not produce TypeScript types. Schema and types are different artifacts. Generate types separately, or pipe the schema through json-schema-to-typescript.
- It will not handle JSON Schema features that require non-data context (vocabularies, custom keywords, $vocabulary in 2020-12). Generated schemas use only the standard meta-schema vocabulary.
Inference happens entirely in this browser. You can safely paste production payloads — they do not leave the page.
Frequently asked questions
Why is my field marked as type ["string", "null"]?
The field was string in some samples and null in others. JSON Schema requires explicit nullability — there is no "nullable" keyword in Draft 7 (Draft 2020-12 added it informally). The union type list is the cross-draft-compatible way.
What is the difference between "type": "number" and "type": "integer"?
"integer" is a subset of "number" — whole numbers only. 42 validates against both; 3.14 validates only against "number". The generator picks "integer" if every sample value has no fractional part. Override if your domain allows fractional values you have not seen yet.
Do I need to include $schema in my schema?
Strongly recommended. The $schema keyword tells the validator which draft to use. Without it, AJV defaults to the version it was compiled with, which may not match your authoring assumption. Always include it for new schemas.
How do I express "exactly one of A, B, or C"?
oneOf in JSON Schema. Different from anyOf (one or more) and allOf (all). Use oneOf for tagged unions where exactly one variant applies; discriminator-based unions (OpenAPI extension) compile to oneOf with a constant discriminator field.
Should I set additionalProperties: false?
Depends on policy. For internal APIs you control end-to-end: yes (catch typos early). For consumer-facing APIs where you might add fields later: no (or use unevaluatedProperties in 2020-12 for nested control). Decide once per API and document it.
Can I reference one schema from another?
Yes — $ref points to a schema by URI or JSON pointer. For inline definitions, put subschemas in $defs (Draft 2019+) or definitions (Draft 7) and reference them as { "$ref": "#/$defs/Address" }. The generator can extract repeated subschemas — enable the "extract types" option.
Related tools
Generate TypeScript interfaces from JSON data. Support for nested objects, arrays, optional properties. Free online JSON to TS interface generator
Compare two JSON documents with visual tree diff. Highlight added, removed, modified nodes. Expandable tree view. Free online JSON comparison tool
Format and beautify JSON, XML, CSS, HTML, JavaScript, SQL code. Auto-indent and syntax highlight. Free online code beautifier and formatter
Learn how AI language models work. Visualize tokenization, simulate temperature sampling, count tokens, build prompts. Interactive LLM tutorial and prompt engineering helper
Generate mock API responses with fake JSON data. Create realistic REST API test data. Free mock server response generator for developers
Convert data between JSON, CSV, YAML, XML, TOML formats online. Free data format transformer with syntax validation and pretty printing
Last updated · E-Utils editorial team