How to Create a JSON Schema (From an Example)
A JSON Schema describes the shape of your JSON — what fields exist, their types, and which are required — so you can validate data automatically in an API or config. The fastest way to write one is to start from a real example and let a generator infer it.
Generate one from your data
Paste an example object into the JSON to JSON Schema generator and get a draft-07 schema with inferred types and required fields — then tweak it to taste. It runs in your browser, so nothing is uploaded.
Example
This JSON:
{ "id": 1, "name": "Alex", "active": true }produces this schema:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"id": { "type": "integer" },
"name": { "type": "string" },
"active": { "type": "boolean" }
},
"required": ["id", "name", "active"]
}What the parts mean
- type — the value's type: string, integer, number, boolean, object, array, or null.
- properties — the fields of an object and their sub-schemas.
- required — the fields that must be present. Remove a field from this list to make it optional.
- items — the schema each element of an array must match.
After generating — refine it
From a single example, every field is marked required. Edit the required array to drop optional fields, and add constraints like minLength, format, or enum where you need stricter validation. Validate the JSON itself first with our JSON Formatter, and if you also need types, try JSON to TypeScript.
FAQ
Which draft version is generated?
Draft-07 — the most widely supported version across validation libraries like Ajv.
Are all fields required by default?
Yes, since they all appear in your example. Edit the generated required list to make fields optional.
Is my data uploaded?
No — the schema is generated entirely in your browser.
Try the JSON to JSON Schema
Generate a JSON Schema from an example JSON object.
