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("^[\"\\(\\[]+|[\"\\)\\(]]+$", "");

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.

2 Answers 2


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, 2017 at 11:34

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 and acknowledge you have read our privacy policy.

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