JSON Schema Generator
Paste sample JSON and get a draft 2020-12 JSON Schema with merged array items, honest required lists and detected string formats.
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"users": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string",
"format": "uuid"
},
"name": {
"type": "string"
},
"email": {
"type": [
"string",
"null"
],
"format": "email"
},
"age": {
"type": "number"
},
"tags": {
"type": "array",
"items": {
"type": "string"
}
},
"createdAt": {
"type": "string",
"format": "date-time"
},
"website": {
"type": "string",
"format": "uri"
}
},
"required": [
"id",
"name",
"email",
"age",
"tags",
"createdAt"
]
}
},
"total": {
"type": "integer"
}
},
"required": [
"users",
"total"
]
}Why generate a schema from sample JSON
JSON Schema describes what a valid document looks like: which fields exist, their types, which are mandatory and what format strings follow. Validators such as Ajv (JavaScript) or jsonschema (Python) use it to reject bad API payloads, editors use it for autocompletion in config files, and OpenAPI reuses it for request and response bodies. Writing one by hand for a large payload is slow and error-prone. This tool gives you an accurate first draft from real data, which you then tighten with constraints that only you know (minimum values, enums, patterns).
How to use it
- Paste a representative JSON document into Sample JSON. Include several array elements, ideally ones that show optional and nullable fields.
- The schema appears on the right as you type. Invalid JSON shows the parser error instead.
- Adjust the Options: Detect string formats, Mark all properties optional and Disallow extra properties.
- Click Copy or Download to save schema.json.
Worked example
In the built-in example, a users array holds two objects. Bob has no email (it is null), a decimal age, and an extra website field. The generated schema for the array items is:
"items": {
"type": "object",
"properties": {
"id": { "type": "string", "format": "uuid" },
"name": { "type": "string" },
"email": { "type": ["string", "null"], "format": "email" },
"age": { "type": "number" },
"tags": { "type": "array", "items": { "type": "string" } },
"createdAt": { "type": "string", "format": "date-time" },
"website": { "type": "string", "format": "uri" }
},
"required": ["id", "name", "email", "age", "tags", "createdAt"]
}website is not required because only one of the two users has it; email is required but nullable because both users have the key; age is number because 27.5 is not an integer; and tags gets its item type from Alice's non-empty array. The whole sample validates against the generated schema.
Options explained
- Detect string formats adds format when all sampled values agree. Most validators treat format as an annotation unless format checking is enabled (in Ajv, via the ajv-formats plugin).
- Mark all properties optional removes every required array — useful for PATCH bodies or partial documents.
- Disallow extra properties adds "additionalProperties": false to every object so unknown keys fail validation. Turn it off if the API may add fields later.
Limitations
- The schema can only be as good as the sample. A field that is optional in reality but present in every sample will be marked required.
- It does not infer enums, minimum/maximum, string lengths, patterns or $defs for repeated structures — add those by hand.
- An empty array produces no items schema, so it accepts anything.
- Mixed objects and other types in one array produce a single item schema with a type list rather than separate oneOf branches.
Tips
- Feed it a root array of several real responses to get better required/optional detection.
- Need compile-time types as well? Generate them from the same sample with JSON to TypeScript.
- Check that your sample is valid first with the JSON Formatter, which points to the exact line and column of syntax errors.
Frequently Asked Questions
Which JSON Schema version does this generator produce?
Draft 2020-12, declared with "$schema": "https://json-schema.org/draft/2020-12/schema". The keywords it uses (type, properties, items, required, format, additionalProperties) mean the same in draft-07, so validators such as Ajv can use the output in either mode once the $schema line matches.
How does it decide which properties are required?
A property is required only if it appears in every object sampled at that position. If one array element lacks "website", that key is listed in properties but not in required. Tick "Mark all properties optional" to omit required entirely.
Does it look at every item in an array?
Yes. The shapes of all elements are merged into one items schema, so a field that is a number in one element and null in another becomes "type": ["number", "null"].
Which string formats are detected?
date-time (RFC 3339), date (YYYY-MM-DD that is a real calendar date), email, uri (scheme://…) and uuid. A format is emitted only if every sampled string for that field matches it; otherwise the field is a plain string.
Why is my integer field typed as number?
If any sample has a decimal part (27.5), the field is typed number, which also accepts integers. It is typed integer only when every sample is a whole number.
Is my JSON uploaded anywhere?
No. Parsing and schema inference run entirely in your browser; nothing is sent to a server.
Related tools
- JSON ViewerView, validate and explore JSON with syntax highlighting and interactive tree view
- JSON FormatterFormat and beautify JSON with syntax highlighting and validation
- CSV ↔ JSON ConverterConvert between CSV and JSON formats
- Excel to JSON ConverterConvert Excel, ODS or CSV sheets to JSON — or JSON arrays back to .xlsx. Choose sheet, header row, date and empty-cell handling. 100% client-side.
- JSON to TypeScriptGenerate TypeScript interfaces from JSON objects
- XML ViewerValidate, format, and explore XML documents with an interactive collapsible tree view. Supports .xml, .xsd, .svg, .rss, .plist and any XML-based format. Runs entirely in your browser.
Found a bug or a wrong result? Report it.