JSON Schema Generator (Draft 2020-12)
Generate a JSON Schema (draft 2020-12) from sample JSON: types, required keys, nullable unions, array items and string formats like email and date-time. Free.
Runs entirely in your browser. Your data is never uploaded.
Related Tools
View AllWhat is JSON Schema Generator?
Infer a JSON Schema from an example document. The generator describes every property's type, merges array items into one items schema, lists required keys, marks nullable values with type unions and can detect common string formats.
How to use JSON Schema Generator
- Paste JSON into the JSON input box, or use Load sample or Open file.
- Optionally set a Schema title.
- Toggle Mark keys as required, Detect string formats and Disallow additional properties.
- The JSON Schema output updates as you type; use Copy or Download.
Example
{"id":1,"email":"a@b.co"} {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"email": {
"type": "string",
"format": "email"
}
},
"required": [
"id",
"email"
]
} When to use JSON Schema Generator
Use it as a starting point for API contracts, config validation or form generation. A schema inferred from one sample is only as good as the sample: add constraints like minimum, enum or pattern by hand before using it to validate real data.
How JSON Schema Generator works
The sample is walked recursively and each position collects the JSON types seen (integer, number, string, boolean, object, array, null). Integers mixed with decimals become number; multiple types become a type array such as ["object", "null"]. For arrays of objects, a property is required only if every object has it. Format detection checks strings against patterns for date-time, date, time, email, uuid, uri and ipv4 and only adds format when every value matches. The result declares $schema: https://json-schema.org/draft/2020-12/schema.
Common Use Cases
- Bootstrap a schema for an API request body
- Validate configuration files with ajv or a CI check
- Document the shape of a webhook payload
- Generate forms from a schema in tools that accept JSON Schema
FAQs
Which draft is generated?
Draft 2020-12, declared with the $schema keyword. The keywords used (type, properties, required, items, format, additionalProperties) are also valid in draft-07.
How are optional properties detected?
Only from arrays of objects: if a key is missing in some elements, it is left out of required. For a single object, every key is required when the option is on.
Is format validation enforced?
In JSON Schema format is an annotation by default; validators such as ajv need format validation enabled (ajv-formats).