Parsing complex JSON in script

Shreyoshi1
Giga Contributor

Hi,

I have to read a complex JSON dynamically in my code which is a script being used in Virtual Agent. The JSON looks something like below:

{
"name": "Shreyoshi",
"description": "My Name",
"family": [
{
"id": "1",
"relationship": "Father",
},
{
"id": "2",
"relationship": "Mother",
}
]
}

In my script after reading the JSON, I am doing the below:

var obj = new global.JSON().decode(reqTemp.toString());
gs.info("JSON String " + obj);
for ( var key in obj)
{
gs.info(" key is : " + key + " and value for key is " + obj[key]);
}
For the key="family", the value is being printed as [object Object], how can I read the JSON within the "family" array dynamically, without having to know the exact key?
 
Can anyone help me on this please.
 
Thanks

 

10 REPLIES 10

Willem
Giga Sage

Hi @Shreyoshi 

Hope you are doing well.

Is your question resolved? Or do we need to follow-up on this?

Please mark the answer as correct if it solves your question. This will help others who are looking for a similar solution. Also marking this answer as correct takes the post of the unsolved list.
Thanks.

Kind regards,

Willem