Monday, July 26, 2021

How to extract multiple values from a Json using a condition with Json Extractor

Json extractor in the Jmeter is an important tool in dealing with the Json responses specially in correlation such an application. Sometimes, instances are there that the need is to extract few values from the Json response of a request which satisfies a certain condition. The Json will look like the below.

If the requirement is to take the all OrderID and OrderAmount of an order which is UNPAID state, we can add the Json extractor and write the code to implement the requirement is as follows.

$.orders.List[?(@.OrderStatus=="UNPAID")]..OrderAmount;$.orders.List[?(@.OrderStatus=="UNPAID")]..OrderID

Now the OrderID and Amount can be used subsequent requests.