About the JSON Schema generator
A JSON Schema describes the shape of JSON data: which fields exist, their types, which are required and what format strings follow. It's used to validate API requests and responses, config files and form input, and by OpenAPI to document APIs.
Writing a schema by hand is slow. This generator infers one from a sample document. For arrays it looks at every item, so fields that only some items have become optional, and fields that are sometimes null are marked as nullable.
How to use the JSON Schema generator
- Paste a sample JSON document into the editor, or click Load sample.
- Choose the draft, and whether to mark required fields, detect formats or disallow extra properties.
- Click Generate schema.
- Review the result, adjust it for your rules (for example minimum values or enums), then copy or download it.
Example
Schema for a user object
Input
{"id":42,"email":"ada@example.com","createdAt":"2026-01-15T09:30:00Z","nickname":null,"tags":["admin"]}Output
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"email": {
"type": "string",
"format": "email"
},
"createdAt": {
"type": "string",
"format": "date-time"
},
"nickname": {
"type": "null"
},
"tags": {
"type": "array",
"items": {
"type": "string"
}
}
},
"required": [
"id",
"email",
"createdAt",
"nickname",
"tags"
]
}Formats like email and date-time are detected from the sample values.
Common errors and how to fix them
must NOT have additional properties
A validator such as Ajv rejected a field the schema doesn't list, because additionalProperties is false. Add the field to the schema, or turn strict mode off.
must have required property 'nickname'
The sample had every field, so all of them were marked required. Remove fields that are really optional from the required array.
strict mode: unknown keyword: "$defs"
Your validator expects an older draft. Generate the schema for draft-07, or configure Ajv with the 2020-12 build (ajv/dist/2020).
Good to know
- Whole numbers become
integer; if any sample in a field has decimals, it becomesnumber. - Mark fields as required lists every key present in all samples of an object. A key missing from some array items is left optional.
- Detect formats adds
formatfor strings that look likedate-time,date,email,uri,uuidoripv4, only when every sample matches. - Values that are sometimes
nullget a type list like["string", "null"]. Fields with several different types useanyOf. - The schema is only as good as the sample. Use a sample that includes optional fields and the variety of values your data really has.
Frequently asked questions
Which draft should I choose?
2020-12 is the latest and works with current validators such as Ajv (using its 2020 build). Choose Draft 07 for older tools and many OpenAPI 3.0 setups. The generated keywords are the same; only the $schema line changes.
How do I validate data with the schema?
Use a JSON Schema validator in your language, such as Ajv for JavaScript, jsonschema for Python or networknt for Java. Load the schema, then validate each document against it.
What does 'No extra properties allowed' do?
It adds additionalProperties: false to every object, so data with keys that aren't in the schema fails validation. It's useful for catching typos, but makes the schema stricter when your API adds new fields.