JSON Schema: Checking More Than Syntax
Distinguish valid JSON from valid application data using required properties, types, and a small schema example.
A syntax validator can accept {"age":"twenty"} even when an API expects an integer. JSON Schema describes additional rules for values. A schema validator compares a document against those rules.
A small contract
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"name": { "type": "string", "minLength": 1 },
"age": { "type": "integer", "minimum": 0 }
},
"required": ["name"],
"additionalProperties": false
}
properties defines checks for named fields. required makes name mandatory; defining a property alone does not require it. additionalProperties: false rejects names not listed here. The $schema declaration identifies the dialect used by the schema.
Compare a few documents
| Document | Outcome under this schema |
|---|---|
{"name":"Sam"} |
Passes; age is optional |
{"name":"Sam","age":20} |
Passes |
{"age":20} |
Fails; name is missing |
{"name":"Sam","age":"20"} |
Fails; age is a string |
{"name":"Sam","team":"A"} |
Fails; team is not allowed |
These are all syntactically valid JSON. Use syntax validation first when a document cannot even be parsed.
Using this site
Use the JSON Schema validator for Draft 7 contract checks. Paste your data and schema separately; the tool checks the schema and reports a failing instance path when the document does not match. Local references are supported, but external URLs are not fetched. The ordinary JSON validator checks syntax only; its green status does not certify a schema match.
When integrating a schema validator into your application, select a supported dialect and decide how referenced schemas are supplied. A local-only workflow should supply dependencies explicitly instead of automatically retrieving arbitrary URLs from untrusted schemas.
Continue with the official JSON Schema tutorial. Keep contract checks separate from transformations: silently changing a string into a number can hide a producer’s error.