Interface Test Learning--jmeter processing JSON

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.