Removing Quotes from a String


I have an API that is listing the id of a weather station as an array.

        "id": "037",
        "name": "Field 37 (Nord-NW)",
        "latitude": 39.81953,
        "longitude": -122.01292,
        "elevation": 156,
        "timeZone": "America/Los_Angeles"

I’ve got the following snippet from a user on this forum, but at the moment it is including the Square Brackets around the entire string as well as quotes around each id:

let idList = [ ]
_.each(pm.response.json(), (arrItem) => {

pm.globals.set('idList', JSON.stringify(idList))

This results in the following header:

Which obviously results in an incorrect URL.

Hey @ccowin

You could add something quick like this to the pre-request script of the request that you need to use those values:

pm.globals.set('ids', JSON.parse(pm.globals.get('idList')))

Then use the {{ids}} syntax on the URL.

I’m in a rush so if this doesn’t work I can check back in later to give a better solution. :slight_smile:

That worked perfectly Danny, thanks again.

Would you happen to have a suggestion on how to subdivide these?
For instance in the image above there are several in the image that start as “Anza-####” is there a way to only grab certain values based on a specific format?

Glad it worked for you.

What sort of groups were you looking to divide them into?

Basically I have two groups, Ag Stations and Utility Stations. All the ag stations are a unique 3 or 4 character string and all the utilities are, as above, a 3 or 4 letter string followed by a “-” and then a 4 digit number. So ideally we separate the Ag stations by if it is greater than 4 characters and then again if the first letters in the string are XXX, YYY, or ZZZZ this way I could subdivide the utility stations.