How to fetch the keys of response body in test script

Using below script i could able to fetch value of key in response body , Could you please let me know how can i fetch key from response body ?

var data = JSON.parse(responseBody)
value = data.key

You can use Object.keys like this:

const response = pm.response.json();
const keys = Object.keys(response);
console.log(keys);

JavaScript Documentation: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys

1 Like

Hi vdespa,

This helped me lot, Thank you so much !

1 Like