JSON Schema Generator
Paste one or several JSON samples and the generator infers a JSON Schema you can use to validate new payloads. Detects types, marks fields as required when they appear in every sample, infers enums when values are drawn from a small closed set, and produces output conforming to JSON Schema draft 2020-12.
How to generate a JSON Schema
-
1
Paste sample documents
One or several real payloads: the more variety, the more accurate the inferred schema.
-
2
Pick the draft
Draft 2020-12 (current), draft 07 (widely supported), or draft 04 (legacy OpenAPI).
-
3
Tune inference
Toggle enum inference, required fields strategy (intersection vs union), and whether to mark all fields `required` when only one sample is given.
-
4
Generate
The schema is emitted with `$schema`, `title`, `type`, `properties`, and nested `$ref`s for repeated sub-objects.
What inference does well
- Types: string, number, integer, boolean, null, array, object.
- Nullability: a field that is
nullin one sample and a string in another becomes["string", "null"]. - Array items: homogeneous arrays produce a single
itemsschema; heterogeneous arrays produceprefixItems. - Enums: if all observed values are from a small set (configurable, default 10 distinct values), emits an
enum. - Required: with multiple samples, the intersection of keys becomes
required; with one sample, all keys are required unless you opt out. - Formats: strings matching ISO-8601 dates, emails or URIs get an inferred
format.
What inference cannot know
- Intent vs example: a sample
age: 25inferstype: integer, but cannot know you also acceptnull. Pass multiple samples that cover edge cases. - Constraints:
minLength,maximum,pattern, you have to add these by hand. Inference does not guess limits from samples. - Business logic: “exactly one of these three fields must be set” requires
oneOf, not inferrable. - References: the generator emits a flat schema. If you want to factor repeated shapes into
$defs, do that after generation.
Example output
From a single sample:
{ "name": "Alice", "age": 30, "tags": ["admin", "user"] }
The inferred schema (draft 2020-12):
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"name": { "type": "string" },
"age": { "type": "integer" },
"tags": { "type": "array", "items": { "type": "string" } }
},
"required": ["name", "age", "tags"]
}
Common mistakes
- Inferring from one sample. The schema will over-fit, every field becomes required, no null tolerance. Always feed at least 5-10 varied samples.
- Using
integerwhen you meantnumber. If any sample has a decimal, the inferred type becomesnumber; if all are whole, it becomesinteger. For fields that could be either, include a decimal sample. - Forgetting optional fields. A field present in 4 of 5 samples but missing from 1 becomes optional, intended. If all 5 samples happen to include it, the schema will mark it required even though it is actually optional in your API.
Frequently Asked Questions
The more the merrier, but 5-10 varied samples typically produce a reasonable schema. With one sample, every field becomes required and nullability cannot be inferred, always provide multiple variants if you can.
Draft 2020-12 by default. Draft 07 and 04 are available for OpenAPI 3.0 compatibility (which uses a draft 05/07 subset).
No. Inferring sensible constraints from samples would over-fit the schema. Add minLength, maximum, pattern etc. manually after generation based on your business rules.
Yes. If you paste a JSON array, the generator treats each element as a separate sample and produces a schema describing an individual element, not the outer array. Toggle “treat as array container” if you want the outer array’s shape instead.
Related Tools
ASCII Table Reference
Full ASCII table from 0 to 127 with decimal, hex, octal, binary, standard names and HTML numeric-reference notation, including NUL, LF and DEL.
Color Palette Generator
Generate monochromatic, analogous, complementary, triadic or tetradic color palettes from a base HEX color and export copy-ready CSS variables.
HTML Character Reference
Searchable list of HTML entities, their named and numeric codes, and a one-click copy for special characters and symbols.
FPS Counter
Measure browser FPS with requestAnimationFrame, smoothing, min/max frame rate, warnings and an optional graph. Runs locally with no upload or API.
HEX Color Picker
Pick or enter a HEX colour and get RGB, HSL, approximate CMYK, relative luminance and contrast ratios against white and black.
JSON Formatter
Paste JSON to pretty-print with 2 or 4 spaces, minify it to compact output, or run a quick syntax check before copying the result.
Tool available in other languages
- JSON-schemagenerator [SV]
- مولّد مخطط JSON [AR]
- Générateur de schéma JSON [FR]
- Generator JSON Schema [ID]
- JSON-Schema-Generator [DE]
- JSON 스키마 생성기 [KO]
- JSON-schemagenerator [NL]
- JSONスキーマジェネレーター [JA]
- เครื่องมือสร้าง JSON Schema [TH]
- Generator schematów JSON [PL]
- Generador de Esquema JSON [ES]
- Trình tạo JSON Schema [VI]
- Gerador de Esquema JSON [PT]
- Generatore di JSON Schema [IT]
- Генератор JSON-схем [RU]
- JSON Şema Oluşturucu [TR]
- JSON 模式生成器 [ZH]