JSON Schema Generator
Infer a draft 2020-12 JSON Schema from a JSON sample.
About JSON Schema Generator
Generate a JSON Schema (draft 2020-12) from a JSON sample, with types, required properties, array items and date formats inferred as you type.
How to use
- Paste a JSON sample, or load a
.jsonfile (up to 5 MB). Any JSON value is accepted; an object or an array of objects gives the most useful schema. - Choose which properties are required. "Keys in every object" requires a key only when every object in the same position has it; "all keys" requires every key that was seen.
- Tick "additionalProperties: false" to make every object reject keys that the sample does not have.
- The schema updates as you type. Copy it, or Download it as a
.schema.jsonfile.
What it does
| JSON | Schema |
|---|---|
| string | "type": "string" |
YYYY-MM-DD string |
also "format": "date" |
date-time string with seconds and a zone, such as 2024-01-31T10:00:00Z |
also "format": "date-time" |
| integer | "type": "integer" |
| other number | "type": "number" |
| boolean | "type": "boolean" |
| null | "type": "null" |
| object | "type": "object" with properties and required |
| array | "type": "array" with items |
- All elements of an array are merged into one
itemsschema, and the objects among them are merged key by key, so a list of records gives one record schema. An empty array gets noitems. - When one position holds several types,
typeis a list:["string", "null"]for a string that is sometimes null,["integer", "string"]for a mixed array. Integers mixed with other numbers arenumber. formatis added only when every string in that position is a valid date or date-time, so2024-02-30is not labelled a date.- The schema declares the 2020-12 draft in
$schema. In "keys in every object" mode the sample always validates against its own schema. - It does not infer
enum,pattern,minimum,maxLength,$refand$defs, tuples, titles or descriptions, and it detects no formats other than the two above. A schema made from one sample describes that sample, so review it before using it as a contract.
Example
{ "id": 1, "joined": "2024-01-31" }
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"joined": {
"type": "string",
"format": "date"
}
},
"required": [
"id",
"joined"
]
}
Privacy
Inference runs in the page. A dropped file is read locally, no request is made, and nothing is stored.
Frequently asked questions
- What is JSON Schema used for?
- It describes the shape of JSON data: which properties exist, their types and which are required. Validators use it to check API requests, configuration files and form data, and editors use it for autocompletion.
- How do I make a property nullable in JSON Schema?
- List null as one of its types: "type": ["string", "null"]. The nullable keyword belongs to OpenAPI 3.0, not to JSON Schema, and standard validators ignore it.
- What does additionalProperties: false do?
- It makes an object invalid when it has a property that is not listed under properties or matched by patternProperties. Without it, JSON Schema allows extra properties.
- How do I mark a property as required in JSON Schema?
- Add its name to the required array of the object schema, next to properties. A property that is listed under properties but not in required may be left out, though when present it must still match its schema.