I have a an object PARENT defined like the following
function PARENT(name, childs){
this.name=name;
var childsArray=New Array();
childs.forEach(function(child_info) {
childsArray.push(new CHILD(child_info));
})
this.childsArray=childsArray;
}
Then there is another object CHILD defined as
function CHILD(_child_info) {
this.name = child_info.name;
this.age = child_info.age;
}
Given an array of PARENT objects I would like to get the following json object
[
{name:"parent 1 name",
childs : [
{
name:"child 1 name",
age:"child 1 age"
},
{
name:"child 2 name",
age:"child 2 age"
},
{
name:"child 3 name",
age:"child 3 age"
}
]
}, ...
{name:"parent n name",
childs : [
{
name:"child 1 name",
age:"child 1 age"
},
{
name:"child 2 name",
age:"child 2 age"
}
]
}
]
but when I try to stringify the array of PARENT I get an empty JSON object {}
How can I achieve this?