JSON Schema is a declarative language for annotating and validating JSON documents. It describes the expected structure, data types, required fields, and constraints of JSON data, enabling automated validation and documentation.
JSON Schema uses JSON itself to describe the structure of other JSON documents. You define a schema with keywords like type, properties, required, minimum, maximum, pattern, and enum. Tools and libraries validate JSON documents against the schema, reporting any violations. JSON Schema is language-independent and widely supported.
You write a JSON Schema document that describes the expected structure. For example, { type: 'object', properties: { name: { type: 'string' }, age: { type: 'integer', minimum: 0 } }, required: ['name', 'age'] }. Any JSON document matching this schema must have a string name and non-negative integer age. Validators in every language check documents against the schema.
No. JSON Schema validates JSON data at runtime. TypeScript types are compile-time only. JSON Schema works in any language, while TypeScript is a compile-time type system.
Popular frameworks integrate JSON Schema validation: Express.js (express-json-validator-middleware), Python FastAPI (pydantic), and .NET (Newtonsoft.Json.Schema).