When submitting an order to an API we get a Json response containing:

"AMLResults": [
        "amlResult": [
                "addresses": [
                        "flatNo": "Flat 1",
                        "houseNumber": "32",
                        "line1": "Ayr Street",
                        "line2": "",
                        "town": "GLASGOW",
                        "postcode": "G21 4DG"

And then I'm trying to test that the address is returned and formatted correctly

let amlResult = {};
pm.test("response should contain a formated client address",function(){
jsonData = pm.response.json();
addresses = amlResult.addresses;
    pm.expect(addresses).to.have.property('flatNo', 'Flat 1');
    pm.expect(addresses).to.have.property('houseNumber', '32');
    pm.expect(addresses).to.have.property('line1', 'Ayr Street');
    pm.expect(addresses).to.have.property('line2', '');
    pm.expect(addresses).to.have.property('town', 'GLASGOW');
    pm.expect(addresses).to.have.property('postcode', 'G21 4DG');

However I keep getting the following failure response:

response should contain a formated client address | AssertionError: expected {} to have property 'addresses'

Any help would be appreciated.

2 Answers 2


Firstly, at


amlResult is an empty object, defined outside the test.

You may want something like this:

const firstAmlResult = jsonData.AMLResults[0];

Now you can inspect this AML Result object:

const result = firstAmlResult.amlResult[0]

const address = result.addresses[0]
pm.expect(address ).to.have.property('flatNo')
pm.expect(result.flatNo).to.eql('Flat 1')

However, for all to.have.property checks, a better approach would be a Schema Validation. Tip #4 of this blog post explains it.


Validating by JSON Path Match:

var jsonData = pm.response.json();
pm.test("Check for house number", function () {

You can also use an array find function.

var jsonData = pm.response.json();
var result = jsonData.find(x =>x.AMLResults.amlResult.addresses.flatNo ==="Flat 1");
pm.environment.set("houseNumber", result.houseNumber);

You'll look for the object where flatNo is "Flat 1"
Store the other values like houseNumber in a variable of set it as an environment variable.

So you can validate their value:

var jsonData = pm.response.json();
pm.test("Check if houseNumber is correct", function () {
    var houseNumber = pm.environment.get("houseNumber "); 
    pm.expect(houseNumber ).to.eql(32);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.