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

1 Like

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

3 Likes

Hi vdespa,

This helped me lot, Thank you so much !

2 Likes