I have a json response like this and I would like to count how many Friend Groups are in MyFriends array (in my case I expect the code to return 7) :
I tried following but it throws tis error--
TypeError: Cannot read properties of undefined (reading '0')
var data = pm.response.json().MyFriends[0].FriendGroupProperties;
pm.test('Number of friends = ' + MyFriends.length, function () {
pm.expect(data.length).to.equal(7);
});
I also tried this but it also throws
TypeError: Cannot convert undefined or null to object
error :
var data = pm.response.json().MyFriends;
var count = Object.keys(data).length;
console.log("The number of expected friends in the response body is: " + count);
console.log(`Number of Friends: ${_.size(data)}`)
Is there anyone who can help me with this?