Bird
Raised Fist0
Postmantesting~20 mins

JSON Schema validation in Postman - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
JSON Schema Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the result of this JSON Schema validation?
Given this JSON Schema and JSON data, what will Postman report after validation?
Postman
{
  "type": "object",
  "properties": {
    "name": {"type": "string"},
    "age": {"type": "integer", "minimum": 18}
  },
  "required": ["name", "age"]
}

Data:
{
  "name": "Alice",
  "age": 17
}
AValidation fails because 'age' is less than the minimum 18.
BValidation fails because 'age' is not an integer.
CValidation passes successfully.
DValidation fails because 'name' is missing.
Attempts:
2 left
💡 Hint
Check the 'minimum' constraint for the 'age' property.
❓ assertion
intermediate
2:00remaining
Which assertion correctly validates the JSON response schema in Postman?
You want to assert that the response JSON has a 'status' string and an 'items' array. Which Postman test script assertion is correct?
Postman
const schema = {
  type: 'object',
  properties: {
    status: { type: 'string' },
    items: { type: 'array' }
  },
  required: ['status', 'items']
};
Apm.test('Schema is valid', () => pm.response.to.have.jsonSchema('schema'));
Bpm.test('Schema is valid', () => pm.response.to.have.jsonSchema(schema));
Cpm.test('Schema is valid', () => pm.response.to.have.jsonSchema({}));
Dpm.test('Schema is valid', () => pm.response.to.have.jsonSchema());
Attempts:
2 left
💡 Hint
The schema variable must be passed as an object, not a string or empty.
🔧 Debug
advanced
2:00remaining
Why does this JSON Schema validation fail unexpectedly?
This schema expects a property 'email' as a string with format 'email'. The data has a valid email string. Why does validation fail?
Postman
{
  "type": "object",
  "properties": {
    "email": {"type": "string", "format": "email"}
  },
  "required": ["email"]
}

Data:
{
  "email": "user@example.com"
}
AThe 'required' array is missing the 'email' property.
BThe 'email' string is invalid because it lacks a domain.
CThe 'format' keyword is not supported by Postman's JSON Schema validator, causing failure.
DThe 'type' of 'email' should be 'email' instead of 'string'.
Attempts:
2 left
💡 Hint
Check Postman's support for JSON Schema format validation.
🧠 Conceptual
advanced
2:00remaining
What is the main purpose of JSON Schema validation in API testing?
Choose the best explanation for why testers use JSON Schema validation in Postman or similar tools.
ATo check that the API response structure and data types match expected definitions.
BTo verify the API response time is within limits.
CTo ensure the API server is running without errors.
DTo test the API authentication mechanism.
Attempts:
2 left
💡 Hint
Think about what JSON Schema describes.
❓ framework
expert
3:00remaining
How to implement JSON Schema validation in a Postman test script for nested objects?
Given this schema with nested objects, which Postman test script correctly validates the response?
Postman
const schema = {
  type: 'object',
  properties: {
    user: {
      type: 'object',
      properties: {
        id: { type: 'integer' },
        profile: {
          type: 'object',
          properties: {
            email: { type: 'string' },
            active: { type: 'boolean' }
          },
          required: ['email', 'active']
        }
      },
      required: ['id', 'profile']
    }
  },
  required: ['user']
};
Apm.test('Nested schema validation', () => pm.response.to.have.jsonSchema(schema.required));
Bpm.test('Nested schema validation', () => pm.response.to.have.jsonSchema(schema.user));
Cpm.test('Nested schema validation', () => pm.response.to.have.jsonSchema(schema.properties.user));
Dpm.test('Nested schema validation', () => pm.response.to.have.jsonSchema(schema));
Attempts:
2 left
💡 Hint
Pass the full schema object to the assertion, not parts of it.

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

  1. Step 1: Understand JSON Schema validation role

    JSON Schema validation is used to verify that the data structure matches what is expected.
  2. Step 2: Relate to Postman usage

    In Postman, it helps confirm the API response format is correct, catching errors early.
  3. Final Answer:

    To check if the API response data matches the expected format -> Option D
  4. 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

  1. Step 1: Recall JSON Schema syntax for type

    JSON Schema requires property names and string values to be in double quotes.
  2. Step 2: Check each option's syntax

    "type": "string" uses double quotes correctly for both key and value, matching JSON standards.
  3. Final Answer:

    "type": "string" -> Option A
  4. 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}?
const schema = {
  type: "object",
  properties: {
    name: { type: "string" },
    age: { type: "integer" }
  },
  required: ["name", "age"]
};

pm.test("Validate response schema", () => {
  pm.response.to.have.jsonSchema(schema);
});
medium
A. Test fails because age is not a string
B. Test passes because response matches schema
C. Test fails because required fields are missing
D. Test fails due to syntax error in schema

Solution

  1. Step 1: Compare response data types with schema

    Response has "name" as string and "age" as integer, matching schema types.
  2. Step 2: Check required fields presence

    Both "name" and "age" are present in response, fulfilling required array.
  3. Final Answer:

    Test passes because response matches schema -> Option B
  4. Quick Check:

    Response matches schema = test passes [OK]
Hint: Match data types and required fields to schema for pass [OK]
Common Mistakes:
  • Confusing integer with string type
  • Ignoring required fields presence
  • Assuming syntax error without checking
4. You wrote this JSON Schema in Postman test but the validation always fails:
const schema = {
  type: "object",
  properties: {
    id: { type: "number" },
    email: { type: "string" }
  },
  required: ["id", "email"]
};

pm.test("Check schema", () => {
  pm.response.to.have.jsonSchema(schema);
});
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

  1. Step 1: Understand JSON Schema number vs integer types

    JSON Schema distinguishes "number" (any number) and "integer" (whole numbers). API returns whole number 123.
  2. 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.
  3. Step 3: Consider common Postman issue

    Postman JSON Schema validation is strict; using "number" for integer values can cause mismatch.
  4. Final Answer:

    The type "number" should be "integer" for whole numbers -> Option A
  5. 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?
hard
A. { "type": "object", "properties": { "tags": { "type": ["array", "null"], "items": { "type": "string" } } }, "required": [] }
B. { "type": "object", "properties": { "tags": { "type": "array", "items": { "type": "string" } } }, "required": ["tags"] }
C. { "type": "object", "properties": { "tags": { "type": "array", "items": { "type": "string" } } }, "required": [] }
D. { "type": "object", "properties": { "tags": { "type": "array", "items": { "type": "string" }, "minItems": 1 } }, "required": [] }

Solution

  1. Step 1: Understand optional field with empty array allowed

    The "tags" field can be missing or present as an empty array or array of strings.
  2. Step 2: Analyze each option

    { "type": "object", "properties": { "tags": { "type": "array", "items": { "type": "string" } } }, "required": [] } allows "tags" as array of strings, not required (can be missing). { "type": "object", "properties": { "tags": { "type": "array", "items": { "type": "string" } } }, "required": ["tags"] } requires "tags" always. { "type": "object", "properties": { "tags": { "type": ["array", "null"], "items": { "type": "string" } } }, "required": [] } allows null type which is not needed. { "type": "object", "properties": { "tags": { "type": "array", "items": { "type": "string" }, "minItems": 1 } }, "required": [] } requires at least one item (minItems:1), disallowing empty array.
  3. Final Answer:

    { "type": "object", "properties": { "tags": { "type": "array", "items": { "type": "string" } } }, "required": [] } -> Option C
  4. Quick Check:

    Optional field with empty array = not required, no minItems [OK]
Hint: Use empty required array and no minItems for optional empty arrays [OK]
Common Mistakes:
  • Making field required when optional
  • Adding minItems disallowing empty arrays
  • Allowing null when not needed
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard