How to remove Double Quotes in Data Driven for GET Method

Hello Maam/Sir.

Absolute newbie for Postman.

I’m currently having an issue on reading datadriven values that are enclosed in double quotations using csv file. Sample datadriven in csv file:

pageNumber
“2”
“3”

I already declared variables in local environment, in the endpoint and in the Params

And here’s my javascript code for reading the data. I tried to use the .slice function to remove the double quotes when reading the values in the csv file.

parameters = [‘pageNumber’]

for (i=0; i<parameters.length; i++)
{
readValueInCSV = pm.iterationData.get(parameters[i]);
console.log ("Value of pageNumber: " + readValueInCSV);

temp = readValueInCSV;
temp = temp.slice(1, temp.length-1);
console.log ("Value of pageNumber after slice: " + temp);
pm.environment.set(parameters[i], temp)

}

After running the datadriven, the double quotations were actually removed in the local environment. Please see screenshot below:

However, based on the results the endpoint fetched, there were still characters displayed. See screenshot below (these diamonds with question marks).

My point is… I want to read datas enclosed in double quotation marks and store them in local environment variables that can be passed to the Params and using only GET Method.

My expected endpoints displayed should be like these:
GET https://reqres.in/api/users?page=2
GET https://reqres.in/api/users?page=3

instead of:
GET https://reqres.in/api/users?page=�2�
GET https://reqres.in/api/users?page=�3�

No need to use slice, just use parseInt when you store the environment variable.

Thanks for the response, but i really need the data to be string. I don’t need
to parseInt anything.

Also, I only used reqres.in website as an example. The data I needed are supposed to be combinations of strings and numbers.

For example:
“B203”, “999P”, “888B”, “GHS9”, “23IO” etc.

I’ve tested this with Postman Echo and I’m not able to replicate your issue.

The data file looks like this, and the numbers are enclosed in strings.

image

(Can you preview your CSV file in the runner, is it the same as above, or does there appear to be extra characters included?)

The request looks like this…

image

I have the following in the pre-request script.

image

This appears to run ok, and doesn’t seem to be adding extra quotes to the query parameter value.

image

data is a special variable which will show you the current line the CSV file as a JSON object. (Pretty much the same as pm.iterationData).

Hi Sir,

Sorry for the late response. I finally got it! Thank you very much for informing me about that “data” special variable. My concern has been completely answered.

I was able to traverse and loop through all the items in the JSON file by using the data variable.

Also, my mistake because i got a different double quotes after i opened it in notepad++. That’s why in Postman they displayed diamonds with question marks.
image

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.