Extract response field by providing Json path in a variable

Hi, I’m trying to extract a particular field value in the response body using below script under Tests. Response body field path ‘appliedRules[0].resultType’ is supplied in the test data sheet column ‘responsefield’, since the field path changes for each iteration.

var jsonData = JSON.parse(responseBody);
var jsonField = pm.iterationData.get("responsefield");

pm.test("Error message validation", function () {
    pm.expect(jsonData[0].jsonField).to.eql(pm.iterationData.get("error message"));

Assertion fails while collection run saying “expected undefined to deeply equal…”. The problem here is it looks for jsonField instead of value in jsonField variable. I tried with providing $ infront of variable, still it fails. Kindly help

You can’t use dotted notation for this.

You can however use bracket notation (and also mix between the two).


This should treat jsonField as a variable.

Thank you very much Mike for the quick response. It works

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.