Parsing responseBody with json key having Dots (.)

Hi,

Sorry if this is already addressed earlier in the forum, I am working on automating some flows and I need to get the values saved in some variables for a few of the keys in the response. My problem though is the keys have Dots in the name: For example, this is a snippet of the response Body, so I am not sure if I need to escape the Dots, since it might confuse with the hierarchy. Is that correct? For example, how do I get the value of versa-tasks.task-status saved in a variable in the below snippet?

“versa-tasks.task”: {
“fdn”: null,
“voaeid”: null,
“moreInfoMessages”: null,
“endTimeStamp”: 1573116810452,
“scheduledTimeStamp”: null,
“versa-tasks.id”: 6,
“versa-tasks.task-name”: “Deploy”,
“versa-tasks.object-name”: “Org deploy using workflow”,
“versa-tasks.domain-name”: “PROVIDER”,
“versa-tasks.user”: “Administrator”,
“versa-tasks.task-description”: “Deploy Org Workflow: Demo1”,
“versa-tasks.task-status”: “COMPLETED”,
“versa-tasks.percentage-completion”: 100,

Thanks,
Suraj

1 Like

Welcome to the community @surajc :wave:

You can use the square bracket syntax to access such properties.

Example:

let data = jsonData["versa-tasks.task"]["versa-tasks.task-status"]
1 Like

Great. Thanks a lot @amit. This is what I did:

var jsonData = JSON.parse(responseBody);
postman.setEnvironmentVariable(“taskStatus”,jsonData[“versa-tasks.task”][“versa-tasks.task-status”])

and that worked!

Thanks!

1 Like

thank you, you saved my day

1 Like