Time to put everything into practice. These exercises go from simple to complex. Do them in order. Each one builds on the previous.
Exercise 1: Write a Schema from Scratch
Hit GET https://jsonplaceholder.typicode.com/posts/1 and write a JSON Schema from scratch for the response. Include: required fields, correct types, minimum values for IDs, and minLength for strings.
expected-response.jsonjson
// Expected response shape:
{
"userId": 1,
"id": 1,
"title": "sunt aut facere ...",
"body": "quia et suscipit ..."
}
Exercise 2: Validate in Postman with Ajv
Create a GET request to https://jsonplaceholder.typicode.com/users/1 in Postman
Write a complete schema for the user response (including nested address and company objects)
Validate using Ajv in the Tests tab with allErrors: true
Intentionally break the schema (change "id" type to "string") and observe the error message
Fix the schema and verify the test passes
Exercise 3: Validate Array Response
Hit GET https://jsonplaceholder.typicode.com/posts
Write a schema with root type "array" and items schema for each post
Add minItems: 1 to ensure the array is not empty
Validate in Postman using both tv4 (with checkRecursive=true) and Ajv
Compare the error output between tv4 and Ajv when validation fails
Exercise 4: REST Assured Schema Validation
Create a Maven project with REST Assured and json-schema-validator dependencies
Create a schemas/ folder inside src/test/resources/
Write a schema file for GET /comments (nested postId, id, name, email, body)
Write a TestNG test that validates the response using matchesJsonSchemaInClasspath()
Run the test — it should pass
Modify the schema to make it fail (e.g., change body type to "integer") and observe the error
Exercise 5: Banking Portal Schema
Write a complete schema for the Banking Portal login response. The response includes userId, token, account details with nested holder and address, and a transactions array. Use enum for accountType, pattern for PAN and phone, and additionalProperties: false. Validate in both Postman and REST Assured.
Exercise 6: Auto-Generate and Refine
Hit GET https://jsonplaceholder.typicode.com/users/1 and copy the response
Paste it into https://www.jsonschema.net/ to auto-generate a schema
Compare the auto-generated schema with one you would write manually
List 5 things the auto-generated schema is missing (required, constraints, patterns, etc.)
Tighten the schema manually and test it
For each exercise, first break your schema intentionally. See what the error message looks like. Then fix it. This builds muscle memory for debugging schema failures in real projects.
Key Point: Practice writing schemas from scratch, validating in both Postman and REST Assured, and always test your schema by breaking it intentionally to understand the error messages.