JSON Schema is a declarative language for annotating and validating JSON documents. A schema names expected types, required keys, nested structures, and constraints—so APIs and configs stay consistent.
Remember.
JSON is the data. JSON Schema is the contract that describes that data. Both are written as JSON text.
Motivation
Why Use JSON Schema?
ValidateReject bad payloads before your app crashes
DocumentDescribe fields for humans and code generators
ShareReuse schemas across services with $ref
StandardizeOne contract for OpenAPI, configs, and databases
Compare
Instance vs Schema
The instance is the JSON you store or send. The schema describes what that instance must look like.
Instance (data)
product.json
{
"productId": 1,
"productName": "A green door",
"price": 12.5
}
instance: {"name":"Ada","age":36}
schema type: object
property keys: name, age
How It Works
The instance holds the real values.
The schema only describes allowed shapes.
Validators take both documents as input.
Frequently Asked Questions
JSON Schema is a vocabulary written in JSON that describes the expected shape, types, and constraints of other JSON documents so you can validate and document them.
No. Data (the instance) is the payload. The schema is a separate JSON document that describes what valid instances look like.
New projects usually target draft 2020-12 (or 2019-09). Older APIs may still use draft-07. Set $schema so validators know which rules apply.
Yes for full validation. Browsers have JSON.parse, but JSON Schema needs a validator (Ajv, jsonschema, online tools, or your language’s library).