Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to extract json response data in jmeter using regular expression extractor?

Tags:

json

regex

jmeter

I am just trying to extract json response data using jmeter but not able to do so.
I am getting something like {"authorizationToken":"abcdef"}.
I am trying to get authorizationToken but not able to get this.

Can anyone help me getting this working?

like image 612
Hitendra Avatar asked Feb 23 '12 15:02

Hitendra


People also ask

How do I extract value from JSON?

To extract the name and projects properties from the JSON string, use the json_extract function as in the following example. The json_extract function takes the column containing the JSON string, and searches it using a JSONPath -like expression with the dot . notation. JSONPath performs a simple tree traversal.

Can we extract value from request body in JMeter?

You can use the regular expression extractor to extract the key from the response of your first request and use the extracted key for subsequent requests. We call this JMeter Extract and re-use.

Why do we use regular expression extractor in JMeter?

Regular expressions are popular when testing web applications because they can be used to validate and to perform operations on a response from a web application. In JMeter, the Regular Expression Extractor is useful for extracting information from the response.


1 Answers

Is authorizationToken appearance unique in response (does it appear only once)?

If it does you may simply use Regular Expression Extractor added to the HTTP Request which returns json response, with regex like following:

HTTP Request
    Regular Expression Extractor
    Reference Name: authToken
    Regular Expression: "authorizationToken":"(.+?)"
    Template: $1$
    Match No.: 1

and refer further extracted value as ${authToken}.


But if your case is more complicated and there several appearances of authorizationToken in json response and you have to extract concrete one you may use e.g. BeanShell PostProcessor / BSF PostProcessor added to the same HTTP Request to extract value with beanshell code + json processing library.

If not - the first solution above should help.


UPDATE:

At the moment the most comfortable way to process JSON responses seems to be custom JSON utils for jmeter (JSON Path Assertion, JSON Path Extractor, JSON Formatter) which are also part of Jmeter Plugins.

In this particular case you can use JSON Path Extractor.

like image 138
Aliaksandr Belik Avatar answered Sep 24 '22 09:09

Aliaksandr Belik