Accessing a JSON object with special Characters


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);


But it errors.

New at this and already over my head.


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


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: