vlatko606
vlatko606

Reputation: 1149

Jmeter - How to extract value from the request (not response) using RegEx

I have JSON request as following:

{
    "type": "SIGNUP",
    "data": {
        "userAccountInfo": {
            "email": "[email protected]",
            "password": "qweQwe123!"
        },
        "userAddressInfo": {
            "country": "United States"
        },
        "userPersonalInfo": {
            "firstName": "test",
            "lastName": "test"
        }
    }
}

How can extract [email protected] from the following request, considering the value of the email is always dinamic?

Any help is appreciated!

Upvotes: 0

Views: 76

Answers (1)

Dmitri T
Dmitri T

Reputation: 168082

If you're talking about HTTP Request sampler and the above JSON is in the "Body Data" tab like:

enter image description here

You can extract the email by adding a JSR223 PreProcessor and using the following code there:

vars.put('email', new groovy.json.JsonSlurper().parseText(sampler.getArguments().getArgument(0).getValue()).data.userAccountInfo.email)

It will extract the value you're looking for and store it into ${email} JMeter Variable

enter image description here

More information:

Upvotes: 1

Related Questions