0
0
Postmantesting~20 mins

Schema validation basics in Postman - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Schema Validation 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 Postman test script?

Given this Postman test script validating a JSON response schema, what will be the test result?

Postman
pm.test('Validate user schema', function () {
    const schema = {
        type: 'object',
        properties: {
            id: { type: 'integer' },
            name: { type: 'string' },
            email: { type: 'string', format: 'email' }
        },
        required: ['id', 'name', 'email']
    };
    pm.response.to.have.jsonSchema(schema);
});
ATest passes if response JSON has integer id, string name, and valid email string
BTest fails if response JSON has any extra properties beyond id, name, and email
CTest passes even if email is missing from response JSON
DTest fails if id is a string instead of integer
Attempts:
2 left
💡 Hint

Check what the required array means and how jsonSchema validates types.

assertion
intermediate
2:00remaining
Which assertion correctly validates a JSON array schema in Postman?

You want to validate that the response is an array of objects, each with a required id (integer) and optional name (string). Which assertion is correct?

Apm.response.to.have.jsonSchema({ type: 'array', items: { type: 'object', properties: { id: { type: 'string' }, name: { type: 'string' } }, required: ['id'] } });
Bpm.response.to.have.jsonSchema({ type: 'array', items: { type: 'object', properties: { id: { type: 'integer' }, name: { type: 'string' } }, required: ['id'] } });
Cpm.response.to.have.jsonSchema({ type: 'array', properties: { id: { type: 'integer' }, name: { type: 'string' } }, required: ['id'] });
Dpm.response.to.have.jsonSchema({ type: 'object', properties: { id: { type: 'integer' }, name: { type: 'string' } }, required: ['id'] });
Attempts:
2 left
💡 Hint

Remember the difference between type: 'array' and type: 'object' and where items is used.

🔧 Debug
advanced
2:00remaining
Why does this Postman schema validation test fail?

Examine the test script below. The response JSON is {"id": 5, "name": "Alice"}. Why does the test fail?

Postman
pm.test('Validate user schema', function () {
    const schema = {
        type: 'object',
        properties: {
            id: { type: 'integer' },
            name: { type: 'string' },
            email: { type: 'string', format: 'email' }
        },
        required: ['id', 'name', 'email']
    };
    pm.response.to.have.jsonSchema(schema);
});
AThe schema has syntax errors causing failure
BThe 'id' property is not an integer
CThe 'name' property is not a string
DThe response is missing the required 'email' property
Attempts:
2 left
💡 Hint

Check the required properties and compare with the response JSON.

🧠 Conceptual
advanced
2:00remaining
What does the 'additionalProperties: false' option do in JSON schema validation?

In a Postman JSON schema, what is the effect of setting additionalProperties: false inside an object schema?

AIt makes all properties optional regardless of the 'required' list
BIt allows any extra properties beyond those listed in 'properties' without failing validation
CIt causes the validation to fail if the response JSON contains any properties not listed in 'properties'
DIt disables all schema validation for that object
Attempts:
2 left
💡 Hint

Think about how strict the schema is about unexpected properties.

framework
expert
3:00remaining
How to write a Postman test to validate nested JSON schema with arrays and objects?

You receive a JSON response with this structure:

{
  "user": {
    "id": 10,
    "roles": ["admin", "editor"]
  }
}

Which Postman test script correctly validates that user is an object with integer id and an array roles of strings?

A
pm.test('Validate nested schema', () => {
  const schema = {
    type: 'object',
    properties: {
      user: {
        type: 'object',
        properties: {
          id: { type: 'integer' },
          roles: { type: 'array', items: { type: 'string' } }
        },
        required: ['id', 'roles']
      }
    },
    required: ['user']
  };
  pm.response.to.have.jsonSchema(schema);
});
B
pm.test('Validate nested schema', () => {
  const schema = {
    type: 'object',
    properties: {
      user: {
        type: 'array',
        items: { type: 'string' }
      }
    },
    required: ['user']
  };
  pm.response.to.have.jsonSchema(schema);
});
C
pm.test('Validate nested schema', () => {
  const schema = {
    type: 'object',
    properties: {
      id: { type: 'integer' },
      roles: { type: 'array', items: { type: 'string' } }
    },
    required: ['id', 'roles']
  };
  pm.response.to.have.jsonSchema(schema);
});
D
pm.test('Validate nested schema', () => {
  const schema = {
    type: 'object',
    properties: {
      user: {
        type: 'object',
        properties: {
          id: { type: 'string' },
          roles: { type: 'array', items: { type: 'integer' } }
        },
        required: ['id', 'roles']
      }
    },
    required: ['user']
  };
  pm.response.to.have.jsonSchema(schema);
});
Attempts:
2 left
💡 Hint

Focus on the nested user object and the types inside it.