Reputation: 226
I am trying to extract a json variable from a response data in JMeter. But my response json is starting with a byte order mark so it is not recognized as a valid one. Here's my response json's starting part:
{"error":false,"errorCode":null,"message":"","statusCode":200,"data":{"bigSlider":[{"displayOrder":0,"imageUrl":"https:\/\/6rk3rbju.rocketcdn.com\/image\/banner\/shopping-image\/0108slider-tartismasiz-app.jpg","link":{"t.......
Once I remove that "" from the beginning of the response, I am able to extract json variables. But since I have to process the response with a post-processor in JMeter, I have written a script like this:
def BOM = ""
def responseData = prev.getResponseDataAsString()
if (responseData.startsWith(BOM)) {
responseData = responseData.substring(1)
}
prev.setResponseData(responseData.getBytes('UTF-8'))
But doing this didn't help me but changing the BOM into something different like "»¿"
Could you please help me?
Upvotes: 0
Views: 278
Reputation: 168122
Your code will work only for CP1252, if your file.encoding property is different it won't remove the BOM
ï
, »
and ¿
are 3 characters in CP1252 therefore you need to replace substring(1)
with substring(3)
In general it's better to stick to UTF-8 where possible so I would recommend amending your code as:
def responseData = prev.getResponseDataAsString().replace('\uFEFF', '')
just make sure that JMeter's file.encoding
property is set to UTF-8
More information:
Upvotes: 1