Accessing a JSON object with special Characters

Hi,

Iā€™m trying to access a specific value and the JSON object has a special character (@) and Iā€™m lost about how to get a value within the object.

Iā€™ve tried this:

// save the Etag into an collection variable

let response = pm.response.json().items[0];

let key = response.PreferredFlag.@context.key;

pm.collectionVariables.set(ā€œeEtagā€, key);

console.log(ā€œeEtagā€,pm.collectionVariables.get(ā€œeEtagā€));

But it errors.

New at this and already over my head.

Jeff

let response = pm.response.json().items[0];

response[ā€™@contextā€™].key

Hello @skydart Welcome to Community :slightly_smiling_face:

Since you mentioned you are new to this, I suggest you to print the response in console and try to debug from it.

To reach the intended element, it will help you understand about the array. Here why would you need to access ā€˜PreferredFlagā€™ tag for getting the key.

So it should be

let key = response.@context.key;

But the special characters in the tag name will cause an error and you can try what @praveendvd mentioned.

To know more about Dot and Bracket notation for JS, Please go through this: