Home > Software engineering >  Error parsing JSON api response - numerical array
Error parsing JSON api response - numerical array

Time:11-19

I am trying to parse value from JSON api response in POSTMAN, but the key i need to parse starts with numerical.

Part of response:

"data": {
   "354a24d506af956a0ccf14444b18da38834eabbd": very good,
}

so using:

var jsonData = JSON.parse(responseBody);
postman.setGlobalVariable("poziomoceny", jsonData.data.354a24d506af956a0ccf14444b18da38834eabbd);

gives me error message:

an identifier or keyword cannot immediately follow a numeric literal

i tried using:

postman.setGlobalVariable("poziomoceny", jsonData.data.(354)a24d506af956a0ccf14444b18da38834eabbd);

and also tried to change it:

var po = "354a24d506af956a0ccf14444b18da38834eabbd";
postman.setGlobalVariable("poziomoceny", jsonData.data.po);

which does not either.

How to solve it?

CodePudding user response:

Have you tried this?

jsonData.data[354a24d506af956a0ccf14444b18da38834eabbd]

CodePudding user response:

the escape that actually works was:

postman.setGlobalVariable("poziomoceny", jsonData.data["354a24d506af956a0ccf14444b18da38834eabbd"]);
  • Related