When we do the HTTP interface test, the returned data are JSON strings, JMeter itself does not support the direct processing of JSON strings, if you want to get to the value specified in the return result, it must be obtained through regular expressions, the regular expression is troublesome, the wrong way to get the value, We all know that JSON is key-value so to save value, that jmeter inside can be directly through the key to value it, so that the regular expression is not so troublesome.
If you want to take the value directly from the key, JMeter official has a JSON path extractor plug-in, loaded it can be directly processed JSON, with key to take the value. The plug-in is: http://jmeter-plugins.org/wiki/JSONPathExtractor/, after downloading, the Lib folder into the JMeter directory is OK.
Open JMeter, where the JMeter is version 3.0, create a new call interface HTTP request, and then add the post processor, you can see the JSON path extractor this plug-in, such as:
How to use it, for example, I just called the interface to get the user information, I want to get to the first user_id, the return JSON is this:
123456789101112131415161718 |
{ "Code": "Info":[ { "Age": "id": 7, " Sex": "Male", " username": "myname " }, { "Age": "id": " Sex": "female", " username": "yourname " } ]} |
Analysis of this JSON string, the UserID in the info this list is stored, take the first userid, it is necessary to take the value of info, and then take the first element of info, that is, user information, and then take to the UserID.
The JSON path extractor uses $ to represent the return value of the original interface, taking values such as: so that you can use the key directly to take the value of the JSON, go and try it.
Interface Test Learning--jmeter processing JSON