0

I am trying to access a variable named var1 in the below BSF Script, where var1 is extracted from JSON XPath Extractor:

String abc= vars.get("var1");
abc = abc.replaceAll("^[\"\\(\\[]+|[\"\\)\\(]]+$", "");
vars.put("abc",abc);

After running the script I could not fetch the value of the variable, i.e. the abc variable.

I have referred to How to remove square brackets [] after extracting response using json path extractor? but could not get the value.

My Jmeter version is 3.1.

1

Try out this line, your regex is a little bit flaky:

abc = abc.replaceAll("\\[", "").replaceAll("\\]", "");

Also consider switching to JSR223 Elements and Groovy language as it is the most powerful and performing scripting option as of now, check out Groovy Is the New Black article for details.

  • If this is your article, please say so, so your answer is not flagged as spam. – Kate Paulk Mar 28 '17 at 11:34
0

I added a Debug Sampler, and analysed the result at Response data. I found Jmeter creates a new variable Var_1, which resolved my problem & can be used for further reference.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.