Javascript 数组的数组中哈希中的邮递员检查值

Javascript 数组的数组中哈希中的邮递员检查值,javascript,postman,Javascript,Postman,有没有一种简单的方法可以在postman中检查数组是否包含哈希,其中特定的键必须具有特定的值,如list.keys()中的python: 这很好: pm.test("Schema has userName", function () { var rpos = 0; var apos = 18; pm.expect(jsonData.Resources[rpos].attributes[apos].name).to.eql("userName&

有没有一种简单的方法可以在postman中检查数组是否包含哈希,其中特定的键必须具有特定的值,如list.keys()中的python:

这很好:

pm.test("Schema has userName", function () {
    var rpos = 0;
    var apos = 18;
    pm.expect(jsonData.Resources[rpos].attributes[apos].name).to.eql("userName");
});
但当资源和属性数组中的位置都可以位于任何位置时:

var jsonData = pm.response.json();
var rpos = undefined;
var apos = undefined;
var msg = "not found";
for (var i=0; i<jsonData.Resources.length; i++) {
    for(var j=0; j<jsonData.Resources[i].attributes.length; j++) {
        for (key in jsonData.Resources[i].attributes[j]) {
            if (key == "name" && jsonData.Resources[0].attributes[j][key] == 'userName' ) {
                rpos = i;
                apos = j;
                msg = "jsonData.Resources[" + rpos + "].attributes[" + apos + "]['" + key + "']";
                break;
            }
        }
    }
}
pm.test("Schema has userName (" + msg + ")", function () {
    if(rpos != undefined || apos != undefined) {
        pm.expect(true);
    }
    else {
        pm.expect.fail(false);
    }
});
def username_in_schema():
    if 'Resources' in jsonData.keys():
        for res jsonData['Resources']:
            if 'name' in res['attributes'].keys():
                if res['attributes']['name'] == 'userName':
                    return True
    return False