using jsonPath() to check json objects

I’m trying to test an API which returns json data. I want to check that a returned json object contains expected properties. I’m using jsonPath() to extract the data from the response body and check it against a session property injected by a data feeder.

Example Feeder Data:

I’ve been researching this more and I think I need to create a custom validator. Does anyone have some example code of a custom validator?

is the ‘shape’ of the returned object always the same? ie - are you only looking to “cn” and “id”?

if so, you could just have two json checks if you restructure your feeder

id;cn;transId

7171512,testUser-999;cjxuy4ln10000hgig3rdt5wz0

and then

.check(
status.is(200),
jsonPath("$…id").is("${id}"),
jsonPath("$…cn").is("${cn}")
)

The shape of the object changes. It is not always the same. That is the challenge. I think I need to create a custom gatling validator that can compare object equivalence, instead of exact string matches. Unfortunately, my scala knowledge is limited, but growing.

I’ve been reviewing the gatling.io validator code (https://github.com/gatling/gatling/blob/master/gatling-commons/src/main/scala/io/gatling/commons/validation/Validation.scala) but it is slow going.

Thanks for the reply!