Testing script - how to get value from the proprerty in double nested array

Hi All,

I have a problem with retrieving the “id” value from the property in double nested arry. Is it possible?

Teest Script:
var jsonData = pm.response.json();
console.log(‘Test 1 for jobReqId:’, jsonData.d.results[0].jobReqId);
console.log(‘Test 2 for status > id:’, jsonData.d.results[0].status.id);
console.log(‘Test 3 for status > id:’, jsonData.d.results[0].status.results[0].id);

Test 1 - returns “145”
Test 2 - returns “null”
Test 3 - returns “Cannot read property ‘0’ of undefined”

Any help appreciated!

Hey @piterwy,

Could you replace the image with the raw code please, makes it easier to have a look at the problem locally. :slight_smile:


Hi @dannydainton,

First, I want to Thank You for willing to help!

I have just found the problem:

  • forgot to expand “status” :blush:


  • Test 3 - returns “11397”
  • Test 2 - will not work because of the wrong syntax

Leaving this post - maybe will help somebody…

1 Like

Don’t you mean you forgot to expand the second “results” array?

// Your original failing test:
console.log("Test 2 for status > id:", jsonData.d.results[0].status.id);
// This returns null

console.log("Test 2 for status > id:", jsonData.d.results[0].status.results[0].id);
// This returns "11397"

Yes, this is what I meant - I forgot to expand “status” complex property in the API call.