Burakhan Aksoy
Burakhan Aksoy

Reputation: 323

What's the most efficient way of making hamcrest assertions for a JSON object with many keys?

I am making assertions on a RestAssured's ValidateableResponse class (i.e., xxxyyzz.then().body(matchers)). Here, I have many JSON key-value pairs in this response and I can use .then().body("path",hasKey(operator)) method for each JSON key, however, this is very tiresome. Is there any other,more efficient, way to validate multiple JSON keys?

best,

Upvotes: 0

Views: 490

Answers (1)

Villa_7
Villa_7

Reputation: 547

If you need to validate a list/array of some entities, you can do the following:

   response
      .getBody()
      .jsonPath()
      .getList("data.owner_type")
      .forEach(ownerType -> hasKey("public"));

Upvotes: 2

Related Questions