How to return JSON data in the "Go" jmeter

Source: Internet
Author: User
Tags file copy

As a data interchange format, Json is widely used in network development, especially in Ajax and Restful architectures. Apache 's JMeter is also one of the more popular stress testing tools, but it does not natively provide response processing for Json data. This article assumes that you need to extract some specific data from the Json-formatted data stream returned from the HTTP response header, with the following data format:

{

"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 to extract the data:

Regular expression Extraction

JMeter After you install the regular expression plug-in, you can extract the data from the string in a fixed format, and in this case the expression is as follows:

"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 the third data.

When the JSON data is occasionally required to be processed, the regular expression is an appropriate choice, one of its advantages is that the jmeter itself is built into the JSON processing module. However, reading a regular expression is more complex, especially with some complex JSON data.

JMeter JSON Plugin

Another way to process JsonThe method of data is to use theJmeterPlug-in that can use theJSONPathTo getJsonData at a specific location in the data. Similar to xml  "  xpath    jsonpath  you can use simple expressions to manipulate  json  object.  json path extractor   is an open source add-on  post processor plug-in that can be added to the plugin's  lib  file copy to  jmeter   lib  directory.

The data required for positioning mentioned above can be described using the following jsonpath:

$.members[2].firstname

In JMeter , you only need to open the JSON Path Extractor from the postprocessor menu and enter the variable name and default value as follows:

JSONPath expressions are short and easy to read, and can effectively improve the serviceability of test scripts, which are not installed with standard JMeter .

BeanShell Post Processor

The last method is to borrow JMeter 's feature for BeanShell support, and BeanShell is a lightweight Java-oriented scripting language. BeanShell Post Processor allows you to work with Json data using standard Java syntax , as shown in the following:

Summarize

This article lists three available methods for extracting data from the return values in JSON format, and regular expressions are very advantageous for fast normalization of data in a simple JSON format. The JsonPath plugin can be used to create scripts that can be maintained and modified, but requires additional plug-in installation work. The final BeanShell with the JSON Library is indeed very detailed and relies on the flexibility of the Java language to be further developed.

How to return JSON data in the "Go" jmeter

Related Article

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.