Currently, the most popular approach for API testing is to send a JSON payload file instead of using data with parameters. This post will show how to do JMeter Load Testing with a JSON payload.
To perform sending the JSON payload we need a different configuration. First, we need to add HTTP Header Manager into our HTTP Request in order to set Content-Type as application/json.
We then put the JSON payload into the Body Data section of our HTTP Request Sampler. In our example we are trying to fetch alarm information from the IOT system rest service.
After executing our test we will get the response to our request from the server below.
Extract Data from JSON Response
It is easy to extract the data from the response using JSON Extractor Post Processors.
After adding the JSON Extractor, we need to set in the configuration the specific data we want to extract.
We are adding Debug Sampler to be able to inspect our variable. It’s a very useful Sampler for debugging and should be included in all JMeter scripts when developing the test plan. However, it is not recommended when executing a heavy testing load. Debug Sampler should then be disabled from the test plan because of the impact it can have on the load agent.
After executing the test again we are able to extract the data variable thanks to the Debug Sampler.
In our example, we have covered how to do JMeter Load Testing with a JSON payload for API testing and extract JSON data from the response. We have shown how to use Debug Sampler for inspecting our variables in the test execution. By the way, don’t forget to disable Debug Sampler when scaling your load test.
After completing the test plan you are ready to run this script as you would with any JMeter script using Redline13 or local testing. Apache JMeter is one of the most popular tools for load testing and scaling out your JMeter test plan on the cloud in RedLine13 is easy.