How to handle JSON data in the "Go" jmeter

Source: Internet
Author: User

As a data interchange format, Json is widely used in network development, especially in Ajax and Restful architectures. And Apache's JMeter is a much more popular pressure. TestTool, 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 ExtractionJMeter After you install the regular expression plug-in, you can extract the data from the string in a fixed format, whereas 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 PluginAnother way to process JSON data is to use the JMeter plug-in, which can use JSONPath to get data at a specific location in the JSON data. Similar to XPath in an XML file, JSONPath can manipulate Json objects using simple expressions.  The JSON Path Extractor is an open source plugin that adds a post processor that copies the lib file of the plugin to the JMeter lib directory. The data you need to locate 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 The volume name and default value are as follows: The JSONPath expression is short and easy to read, effectively improving the maintainability of the test script, which is not installed with the standard JMeter. BeanShell Post ProcessorThe 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: SummaryThis 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 handle JSON data in the "Go" jmeter

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.