Abhishek Sharma
Abhishek Sharma

Reputation: 31

How to concatenate string which has double quotes in it (JMeter)

I have a situation where I need to concatenate two strings 1 and 2.

Str1: {"CodeName":"service:batch","data":{"prId":${TestId},"filters":[{
Str2: "tallId":

To look like:

{"CodeName":"service:batch","data":{"prId":${TestId},"filters":[{"tallId":

Have tried:

Str1 = Str1 + "\"tallId\":";

Upvotes: 0

Views: 4008

Answers (2)

Dmitri T
Dmitri T

Reputation: 168197

  1. Building JSON using string concatenation is not the best option
  2. Inlining JMeter Functions and Variables into Script body a very bad practice
  3. Since JMeter 3.1 it is recommended to use JSR223 Elements and Groovy language for any form of scripting in JMeter

So I would recommend reconsidering your approach using Groovy language as it has built-in JSON support so you should be able to create a "good" JSON Object from JMeter Variables without having to worry about quotation marks, commas, etc.

Upvotes: 1

ararar
ararar

Reputation: 983

Put the below code in your beanshell script area:

String Str1 = vars.get("mainString");
String Str2 = "\"teamId\":";
String Str3 = Str1 + Str2;
vars.put("NewString", Str3);

enter image description here

Upvotes: 0

Related Questions