JSON to JSON Schema
Paste a JSON sample and get a JSON Schema describing its types, required properties and nested objects, ready for validation or documentation. Free, no signup, and generated in your browser.
16 lines · processed in your browser, nothing is uploaded
JSON Schema output · root.schema.json
Generated code appears here.Example: JSON to JSON Schema
This JSON sample, with the root type named User, produces the JSON Schema below using the default options.
{
"id": 1024,
"name": "Ada Lovelace",
"email": "ada@example.com",
"active": true,
"score": 98.5,
"tags": [
"admin",
"beta"
],
"address": {
"city": "London",
"postcode": "NW1 6XE"
}
}{
"$schema": "http://json-schema.org/draft-06/schema#",
"$ref": "#/definitions/User",
"definitions": {
"User": {
"type": "object",
"additionalProperties": false,
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "string"
},
"email": {
"type": "string"
},
"active": {
"type": "boolean"
},
"score": {
"type": "number"
},
"tags": {
"type": "array",
"items": {
"type": "string"
}
},
"address": {
"$ref": "#/definitions/Address"
}
},
"required": [
"active",
"address",
"email",
"id",
"name",
"score",
"tags"
],
"title": "User"
},
"Address": {
"type": "object",
"additionalProperties": false,
"properties": {
"city": {
"type": "string"
},
"postcode": {
"type": "string"
}
},
"required": [
"city",
"postcode"
],
"title": "Address"
}
}
}
How to convert JSON to JSON Schema
- 1Paste a JSON object or array of records into the input.
- 2Select JSON Schema as the output.
- 3Name the root type, for example Event.
- 4Copy the schema into a .schema.json file.
- 5Add constraints such as formats, enums or patterns by hand.
Which draft version?
JSON Schema has several drafts, including draft-04, draft-06, draft-07, 2019-09 and 2020-12. The $schema keyword at the top of the output tells validators which one to use, so keep it.
Most validators, such as Ajv, support several drafts, but some keywords changed between versions; for example, definitions became $defs in 2019-09. Check that your validator supports the draft declared in the output.
Required properties and additionalProperties
Properties present in every record of your sample are listed in required; those missing from some records are left out. Paste several records to get an accurate required list.
Decide whether unknown keys are allowed. Setting additionalProperties to false makes the schema strict, which catches typos but rejects new fields the API may add.
What a schema adds beyond types
A sample cannot show rules such as "must be an email" or "one of these three values". Add format, enum, minimum, maxLength or pattern after generating.
The finished schema can validate data in many languages, document an API, or feed other generators.