Postman - Failing to get value from an object that has `:` in the property key

Viewed 191

I'm struggling to get value from an object that has : within the key name of property.

This is how my Response Body looks:

{
    "links": {
        "content": {
            "href": "http://*********",
            "templated": false,
            "type": "application/hal+json"
        },
        "test:search": [
            {
                "title": "Some title",
                "href": "http://*************",
                "type": "application/hal+json"
            }
        ]
    }
}

When I try to get the href value from test:search, Postman is giving me an error:

"Missing ";" before statement".

1 Answers

This should work if you add it to the Tests tab:

_.each(pm.response.json().links['test:search'], (item) => {
    console.log(item.href)
    pm.environment.set('href', item.href)
})

Test Request

If you were to use this to reference the property pm.response.json().links.test:search it would fail to set the variable.

Failed Request

Related