Key name in Json contains a space

How do I get the value from a key that has spaces in name like:

“values”: {
“Request Number”: “REQ000000023077”

Want to do:
postman.setGlobalVariable(“REQ_InstanceId”, jsonData.values.Request Number);

I’ve tried with [ , { ,’ , ", and any combination of brackets and quotes e.g. [‘Request Number’] but everything gives an error like Unexpected Token.

Any clues?
Thanks

The bracket format should work, since it’s standard javascript.

For eg:

let values = { 
	'Request Number': '1234'
};

console.log(values['Request Number']); // 1234

For your case:

postman.setGlobalVariable(“REQ_InstanceId”, jsonData.values['Request Number']);

I have tried that but unfortunately it yields a Syntax error and in my Postman I can see already when defining the Test that it won’t work.
billede
Please see the attached screendump

1 Like

Hey @psorense. That is because you’re using both . and [ to access the field. Use only the [ or simply copy what @singhsivcan mentioned above.

What a difference a dot makes :blush:
Works!
Thanks and sorry for being an ignorant.

@singhsivcan what if in the response the element is array-like and need to fetch the id, please help.
{
“Engagement Model”: [
{
“id”: 45,
“name”: “Test”
}
]
}

You should be able to use a period after the brackets just like normal.

object['Engagement Model'].id

If you struggle with that, you can always just use the bracket notation all the way through.

object['Engagement Model']['id']