JMeter handles json for responses
For the result returned by request 1, which is processed as a parameter of request 2, JMeter provides a regular expression extractor
as follows:
In this way, a certain value of responses can also be obtained through regular expressions
But for most of the results returned by the request, it is json. There is a more convenient plug-in: JSON Extractor
, but you have to download the plug-in first https://jmeter-plugins.org/wiki/JSONPathExtractor/
After downloading and decompressing, put the jar packages in lib and lib/ext into the corresponding location of the installation directory, and restart.
Briefly describe how to use the plugin
The plugin is:
Variable names : name
JSONPath Expression: JSON expression
Match Numbers: which one matches, can be empty, that is, the first
Default Value: the default value when no value is obtained
For example, the return value of a request is:
{"statusCode":200,"data":{"userId":"4a2cbe616eb74f0d99190af072c8dea6","token":"37e7a9e198186f5a443e50e6138a5bd20bd"}}
- 1
Here because the json data is returned, $.data.token
, get the value of the token
But I encountered a pit
and another interface request returned the value:
{"statusCode":200,"data":[{"code":"407949","id":"aa477ad2085d492a99b877d14343d68d","name":"90一中4545"}]}
- 1
Similarly, when using $.data.id
to extract the value of id, it is found that the obtained data is empty. The data of
this response is an array, so $.data[0].id
the first value should be extracted.
as follows: