You are building a house. Before a single brick is laid, the architect hands you a blueprint. It says: 3 bedrooms, 2 bathrooms, kitchen on the left, main door facing east. If the builder delivers a house with 2 bedrooms and the kitchen on the roof — you reject it. The blueprint is the contract.
JSON Schema is the blueprint for API responses. It defines exactly what fields must exist, what types they should be, and what constraints they must follow. Schema validation is the act of checking whether an actual API response matches that blueprint.
Without a blueprint, you are trusting the builder blindly. Without schema validation, you are trusting the API blindly. Both are bad ideas.
Think of schema validation as the spell-check for API responses. You could read every word manually, or let the tool catch problems for you. Schema validation is that tool for API structure.
Q: What is schema validation and why do we need it in API testing?
A: Schema validation checks whether an API response matches a predefined structure (JSON Schema). It validates field names, data types, required fields, and constraints in a single assertion. We need it because checking individual fields misses structural problems — like a field changing from string to integer, a required field disappearing, or unexpected fields appearing. It acts as a contract between the API producer and consumer.
Key Point: Schema validation is the blueprint check for API responses — it validates the entire structure (fields, types, constraints) in one assertion instead of checking fields individually.