Schema and validation
How to validate JSON with JSON Schema
Use JSON Schema to check required fields, data types, arrays, enumerations, and nested response contracts.
Document summary
A practical introduction to generating a starting schema, strengthening constraints, and interpreting validation errors.
Key takeaways
- Use strict, representative input before relying on output.
- Review structure, types, and edge cases instead of checking only visual formatting.
- Continue examples inside the connected Bacodev tool to verify the result.
Schema validates meaning beyond syntax
A JSON parser checks grammar. JSON Schema can also require specific properties, data types, value ranges, patterns, and array item shapes.
Generate a draft from representative data
- 1
Use a response that contains realistic optional and required fields.
- 2
Generate the initial schema.
- 3
Decide which properties are truly required.
- 4
Add constraints such as enum, minimum, pattern, and array limits.
- 5
Test valid and intentionally invalid examples.
Declare the schema draft
| Draft | Use |
|---|---|
| Draft 7 | Broad compatibility with established validators |
| 2019-09 | Modern vocabulary and reference behavior |
| 2020-12 | Current modern draft used by many new systems |
Required and typed properties
{
"id": "42"
}{
"type": "object",
"required": ["id"],
"properties": {
"id": {"type": "integer"}
}
}Read validation errors by path
- Start with the first failing path.
- Check whether the data or schema is wrong.
- Review parent constraints when many child errors appear.
- Do not mark every generated property as required automatically.
- Version schemas with the API contract.
The parts of a schema that matter first
A JSON Schema describes the shape of a document: the allowed type at the root, the properties an object may have, which are required, and the types of array items.
Start with $schema, type, properties, required, and items. Those five keywords cover most validation needs, from API payloads to configuration files.
- $schema declares the schema draft, for example http://json-schema.org/draft-07/schema
- type restricts the value, such as object, array, string, number, or null
- properties lists the allowed keys and their own schemas
- required lists the keys that must be present
- items describes the type of every element in an array
Validate a document against its schema
- 1
Generate a starting schema from an example document with the JSON schema generator.
- 2
Open the JSON schema validator and paste both the document and the schema.
- 3
Read the error report; each violation points to the exact path in the document.
- 4
Fix the document or the schema, then re-validate until the report is clean.
Frequently asked questions
Which JSON Schema draft does the validator support?
The validator follows the widely used draft-07 vocabulary, which covers type, properties, required, items, enum, and the common constraints used in APIs and configs.
What happens when a required property is missing?
Validation fails and the report names the missing property and its path, so you can fix the document without guessing.
Can I generate a schema from my JSON?
Yes. The schema generator infers types, required keys, and item types from a representative example document, giving you a starting point to refine.
Does schema validation upload my files?
No. Both the document and the schema are processed locally in your browser.