What is JSON Schema?
JSON Schema is a vocabulary for describing the shape of JSON data: which fields exist, what types they are, which are required and what constraints apply. Tools use it to validate payloads, generate forms, power editors with autocomplete and document an API.
The core keywords
| Keyword | Purpose |
|---|---|
| type | object, array, string, number, integer, boolean, null |
| properties | Defines each field of an object |
| required | Lists fields that must be present |
| items | Describes the elements of an array |
| enum | Restricts a value to a fixed set |
Generate a schema from a sample
Writing a schema by hand is tedious. Paste a JSON sample into the JSON to JSON Schema Generator and it infers the types, nests objects and arrays, and marks every field as required. Edit the result to loosen constraints where values are optional.
Get your sample right
A schema is only as good as the sample you give it. Include every field, including ones that are sometimes null, and both an object and an array case if the shape varies. If the sample is not valid JSON, fix it first with the JSON Formatter.
Draft choice
Draft 2020-12 is the current standard. Choose Draft-07 only when your tooling is older. Both are widely supported, and the generator can emit either.
Where schemas pay off
- Catching malformed API responses early
- Validating configuration files before deployment
- Documenting an API without writing prose
- Generating forms and editors automatically
If your data is YAML, convert it first with the JSON to YAML tool, then generate a schema from the JSON equivalent.