Extra double quotes are getting added when using jmeter variable to pass value in GraphQL HTTP request ‘Variable’ in Jmeter

Extra double quotes are getting added when using jmeter variable to pass value in GraphQL HTTP request ‘Variable’ in Jmeter


0

I want to send below request in GraphQL HTTP request in Jmeter –

{"pageName":"TEST_SCREEN","section":"TEST_SCREEN","action":{"name":"includeObjects","fields":[{"fieldName":"id_","value":"101"},{"fieldName":"id_","value":"102"},{"fieldName":"id_","value":"103"}]}}

I am generating the value of "fields" dynamically and it can have any number of entries. So I generated value for fields and stored in a variable beforehand like below-

String request = "[";
for (int i = 0 ;i<items.length;i++) {
    if (!"[".equals(request)) {
        request +=",";
    }   
    request += "{"fieldName":"id_","value":""+items[i]+""}";
}
request += "]";
vars.put("ITEMS_ID_REQUEST",request);

Then in the graphQL Sample, under Variables I gave like this-

{"pageName":"NEW_PAGE","section":"NEW_FILTER_PAGE","action":{"name":"includeAction","fields":"${ITEMS_ID_REQUEST}"}}

JMeter is sending below reuest-

{"pageName":"TEST_SCREEN","section":"TEST_SCREEN","action":{"name":"includeObjects","fields":"[{"fieldName":"id_","value":"54794"},{"fieldName":"id_","value":"54795"},{"fieldName":"id_","value":"54796"},{"fieldName":"id_","value":"54797"},{"fieldName":"id_","value":"54798"}]"}}

And my sample is failing. I notice that value of the fields which should be [{..}] is now enclosed in a double quotes which is messing up the json request. I know we have to enclose JMeter variable in double quotes so removing them didn’t work so I tried to escape double quotes but that also isn’t working.
How can I replace the desired value correctly without double quotes?
Thanks in advance!

1 Answer
1


0

Well, I think this is you who adds the "double quotes", not JMeter

"fields":"${ITEMS_ID_REQUEST}"}}                                         
         ^ here              ^ and here

so just remove them and they will go away in your "below request"

Maybe using JsonBuilder will be more convenient for generating JSON than string concatenation?

More information:



Leave a Reply

Your email address will not be published. Required fields are marked *