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: