How to use the JSON Schema Generator
- Paste one representative JSON document. To cover variations, wrap several records in one array; array items are merged.
- Pick draft 2020-12 (default) or draft-07, and toggle string formats, forbid extra properties and merging array items.
- Add constraints a sample cannot show: enum, minimum, maxLength, pattern.
- Test it in the JSON Schema validator against both good and bad documents.
Worked example
A small user record
Input
{"id":1,"email":"ada@example.com","tags":["admin"]}JSON Schema
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"email": {
"type": "string",
"format": "email"
},
"tags": {
"type": "array",
"items": {
"type": "string"
}
}
},
"required": [
"id",
"email",
"tags"
]
}Every key in the sample is marked required; remove keys that may be absent. "format": "email" was added because the value looks like an email (turn off string formats to omit it).
What a generator can and cannot infer
| Rule | Inferred from a sample? | Add by hand |
|---|---|---|
| Types | Yes | |
| Nested properties and items | Yes | |
| required | Yes, but over-eager: every key seen | Trim optional keys |
| additionalProperties | Option: "Forbid extra properties" sets false | Or set it per object |
| enum / const | No | List allowed values |
| format (email, date-time, date, uri, uuid, ipv4) | Yes, for strings that clearly match (option, on by default) | Remove any false positives |
| minimum / maxLength / pattern | No | Add business limits |
Arrays with mixed items
If array items differ, the generator merges them: a key present in only some items is left out of that items schema's required list, and a value seen as both a string and a whole number gets "type": ["string", "integer"] ("number" if any value had a decimal point). For arrays of different kinds of objects, rewrite the result with oneOf and a discriminating property.
Which draft to use
Draft 2020-12 is the current published version and is supported by Ajv, the Python jsonschema package and most modern validators. OpenAPI 3.1 uses 2020-12 as well; OpenAPI 3.0 uses an older, modified subset, so check nullable and exclusiveMinimum if you paste the schema there.
JSON Schema Generator FAQ
What is a JSON Schema used for?
It describes what valid JSON looks like – types, required keys, value limits – so that tools can validate data automatically, generate documentation and forms, and power editor autocomplete.
Can I generate a JSON Schema from an API response?
Yes. Paste the response body. The generator reads one document, so if fields vary between responses, combine them into a single JSON array: merged array items capture optional keys and nullable values.
Why is every property listed as required?
The generator only sees keys that are present in the sample, so it cannot know which are optional. Remove keys from the required array that the API may omit.
How do I disallow extra properties in JSON Schema?
Add "additionalProperties": false next to properties. Validation then fails for any key not declared.
How do I allow null for a property?
Use a type array: "type": ["string", "null"]. In OpenAPI 3.0 use "nullable": true instead.
What draft does the generated schema use?
Draft 2020-12 by default, declared in the $schema keyword at the top. Draft-07 is available in the options for older validators.

