# Concade dynamic variable with pm.response.json() to fetch response value

**URL:** <https://community.postman.com/t/concade-dynamic-variable-with-pm-response-json-to-fetch-response-value/76566>\
**Category:** Help Hub\
**Tags:** variables, collections, scripts\
**Created:** [March 7, 2025, 9:03am UTC](https://community.postman.com/t/concade-dynamic-variable-with-pm-response-json-to-fetch-response-value/76566 "2025-03-07T09:03:29Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![allenheltondev](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/allenheltondev/32/31738_2.png) [@allenheltondev](https://community.postman.com/u/allenheltondev)\
**Post date:** [March 7, 2025, 3:09pm UTC](https://community.postman.com/t/concade-dynamic-variable-with-pm-response-json-to-fetch-response-value/76566/2 "2025-03-07T15:09:14Z")

</div>

I see quite a few problems in the code you posted, but I think I get the gist of what you’re trying to do. You want to dynamically assert that a nested property `N` levels deep equals a value. You can do that with this adjusted script:

```javascript
const responsebody = pm.response.json();

// Assuming sortField looks like this: contact.address.city.town
const sortField = pm.variables.get("sortField");

// Assuming sortValue looks like this: "Building 1"
const sortValue = pm.variables.get("sortValue");
const fields= sortField.split(".");

// I'm not sure where to start or your requirements around array processing, so we'll do it this way.
let currentField = responseBody.response[0];
for(const field of fields) {
  if(currentField) {
    // Dive deeper into the field nest
    currentField = currentField[field];
  }
}

pm.expect(currentField).to.equal(sortValue);

```

This doesn’t feel exactly what you’re doing, but I hope it gets you close. I am having a hard time following your code 😅

I’m more than happy to answer any questions you might have on this!

---

_[View the full topic](https://community.postman.com/t/concade-dynamic-variable-with-pm-response-json-to-fetch-response-value/76566)._
