JMeter on the inside JSON data processing method

Source: Internet
Author: User

http://eclipsesource.com/blogs/2014/06/12/parsing-json-responses-with-jmeter/

Json is developed as a data interchange format in the network. In particular , Ajax and Restful architectures are used more and more widely. Apache 's JMeter is also one of the more popular stress testing tools, but it does not provide the Json Response processing of the data.

In this article, if you need to extract some specific data from the Json -formatted data stream returned from the HTTP response header , the data format is as follows:

{

"Name": "Simpsons Family",

"Members": [

{"FirstName": "Homer", "LastName": "Simpson"},

{"FirstName": "Marge", "LastName": "Simpson"},

{"FirstName": "Bart", "LastName": "Simpson"},

{"FirstName": "Lisa", "LastName": "Simpson"},

{"FirstName": "Maggie", "LastName": "Simpson"}

]

}

Here we use different methods for extracting data:

Regular form Extraction

JMeter After installing the normal form plug-in. The ability to extract data from a string in a fixed format, as shown in this example, as seen below:

"FirstName": "(. +?)"

When the expression is used, all strings that obey the expression are returned, but only one expression is our concern. You can use $1$ as a template, and 3 returns a third data.

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvd3h5exhjmtk5mg==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast ">

When the JSON data is occasionally required to be processed, the normal form is an appropriate choice, one of its advantages is that the jmeter itself is built into the JSON processing module.

But. The reading process is more complex, especially for some complex JSON data.

JMeter JSONPlugins

Another way to process Json data is to use the JMeter plugin. The plug-in can use JSONPath to get data at a specific location in the JSON data.

Similar to XPathin an XML file ,JSONPath is able to manipulate Json using a simple expression object.

JSON Path Extractor is an open source add- on Post The plug-in of the processor allows the plugin to be Lib files are copied to JMeter of the Lib folder is available.

The data required to be located above can be described using jsonpath such as the following :

$.members[2].firstname

In JMeter , you only need to open the JSON Path from the postprocessor menu Extractor You can then enter the variable name with the default value, as seen in the following:

The short and easy-to-read JSONPath expression improves the serviceability of the test script, which is not installed with the standard JMeter .

BeanShell Post Processor

The last method is to borrow JMeter 's feature for BeanShell support, andBeanShell is a lightweight Java scripting language. BeanShell Post Processor agrees to use standard Java syntax to process Json data, Usage for example with what you see:

Summarize

This article lists three available methods for extracting data from the return values in JSON format, which is an advantage of high-speed normalization of data in simple JSON format.

The JsonPath plugin can be used to create scripts that can be maintained for changes. However, additional plug-in installation work is required. The final BeanShell with JSON library In fact, the flexibility of a very specific and dependent Java language can be further developed.

JMeter on the inside JSON data processing method

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.