JSON Schema validation is a way to check if a JSON response matches a defined structure and rules. It ensures the data format is correct.
Click to reveal answer
beginner
How do you use JSON Schema validation in Postman tests?
In Postman, you write a test script that uses the 'pm.expect' function with 'tv4.validate' or 'ajv.validate' to check the response against a JSON schema.
Click to reveal answer
beginner
What is the role of 'required' in a JSON Schema?
The 'required' keyword lists properties that must be present in the JSON data for the validation to pass.
Click to reveal answer
beginner
Why is JSON Schema validation useful in API testing?
It helps catch errors early by verifying the API response structure, making sure the data is complete and correctly formatted.
Click to reveal answer
beginner
What happens if JSON Schema validation fails in a Postman test?
The test will fail, showing an error message that the response does not match the expected schema.
Click to reveal answer
Which keyword in JSON Schema specifies properties that must be present?
Arequired
Bproperties
Ctype
Ditems
✗ Incorrect
The 'required' keyword lists the properties that must exist in the JSON data.
In Postman, which function is commonly used to assert JSON Schema validation?
Apm.sendRequest()
Bconsole.log()
Cpm.expect()
Dpm.response.to()
✗ Incorrect
pm.expect() is used to write assertions, including JSON Schema validation.
What does JSON Schema validation check in API responses?
AServer status
BResponse structure and data types
CResponse time
DNetwork latency
✗ Incorrect
JSON Schema validation checks if the response structure and data types match the schema.
If a JSON Schema validation fails, what is the usual outcome in Postman?
AResponse is ignored
BTest passes silently
CPostman crashes
DTest fails with an error
✗ Incorrect
A failed validation causes the test to fail and shows an error message.
Which of these is NOT a valid JSON Schema data type?
Afunction
Binteger
Cboolean
Dstring
✗ Incorrect
'function' is not a valid JSON Schema data type.
Explain how JSON Schema validation helps improve API testing in Postman.
Think about how validating the shape and content of data helps avoid bugs.
You got /5 concepts.
Describe the steps to add JSON Schema validation in a Postman test script.
Focus on writing the schema and using Postman test functions.
You got /5 concepts.
Practice
(1/5)
1. What is the main purpose of JSON Schema validation in Postman?
easy
A. To create new API endpoints
B. To speed up the API response time
C. To change the API response data automatically
D. To check if the API response data matches the expected format
Solution
Step 1: Understand JSON Schema validation role
JSON Schema validation is used to verify that the data structure matches what is expected.
Step 2: Relate to Postman usage
In Postman, it helps confirm the API response format is correct, catching errors early.
Final Answer:
To check if the API response data matches the expected format -> Option D
Quick Check:
JSON Schema validation = format check [OK]
Hint: Remember: JSON Schema validates data format, not speed or changes [OK]
Common Mistakes:
Thinking it changes API data
Confusing validation with performance
Assuming it creates endpoints
2. Which of the following is the correct way to write a JSON Schema type check for a string in Postman test script?
easy
A. "type": "string"
B. "type": string
C. "type": 'string'
D. type: "string"
Solution
Step 1: Recall JSON Schema syntax for type
JSON Schema requires property names and string values to be in double quotes.
Step 2: Check each option's syntax
"type": "string" uses double quotes correctly for both key and value, matching JSON standards.
Final Answer:
"type": "string" -> Option A
Quick Check:
JSON keys and string values need double quotes [OK]
Hint: Use double quotes for keys and string values in JSON Schema [OK]
Common Mistakes:
Omitting quotes around string values
Using single quotes instead of double quotes
Missing quotes around keys
3. Given this Postman test snippet, what will be the test result if the response JSON is {"name": "Alice", "age": 30}?
The API response is {"id": 123, "email": "user@example.com"}. What is the likely problem?
medium
A. The type "number" should be "integer" for whole numbers
B. The required array should be outside the schema object
C. The response keys are missing quotes
D. The test syntax is incorrect
Solution
Step 1: Understand JSON Schema number vs integer types
JSON Schema distinguishes "number" (any number) and "integer" (whole numbers). API returns whole number 123.
Step 2: Check if "number" type matches whole number
"number" accepts integers generally, but Postman JSON Schema validation requires "integer" for whole numbers like 123.
Step 3: Consider common Postman issue
Postman JSON Schema validation is strict; using "number" for integer values can cause mismatch.
Final Answer:
The type "number" should be "integer" for whole numbers -> Option A
Quick Check:
Use "integer" for whole numbers in schema [OK]
Hint: Use "integer" type for whole numbers in JSON Schema [OK]
Common Mistakes:
Placing required outside schema
Ignoring quotes in JSON keys (not relevant here)
Assuming test syntax error without checking
5. You want to validate an API response in Postman where the "tags" field is an array of strings, but it can be empty or missing. Which JSON Schema snippet correctly allows this?