psorense
(psorense)
March 28, 2019, 10:37am
1
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']);
psorense
(psorense)
March 28, 2019, 12:39pm
3
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.
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.
psorense
(psorense)
March 28, 2019, 12:46pm
5
What a difference a dot makes
Works!
Thanks and sorry for being an ignorant.
akunapar
(avinash)
November 3, 2021, 12:24pm
6
@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']