i am trying to construct a JSON request that has two arrays in it, this is the end result i am looking for:
[
{
"Policy": {
"Channel": "online",
"Credit Score": "20000",
"Car": [
{
"Age": "28",
"AnnualMiles": "15000",
"CarAge": "3",
"Young Driver": "1"
}
]
}
}
]
i am trying to push two objects in the JSON Arrays, one into the root array (i attached this object to a variable called result):
{
"Channel": "online",
"Credit Score": "20000"
}
and the other one into the sub array (i attached this object to a variable called result2):
{
"Age": "28",
"AnnualMiles": "15000",
"CarAge": "3",
"Young Driver": "1"
}
The code i am trying to use is:
policy=new Array()
policy.car=new Array()
policy.push(result)
policy.car.push(result2)
console.log(policy)
console.log(JSON.stringify(policy))
response.status(200).json(policy)
i see that the JS object (policy) is constructed in the structure i was looking for, however the JSON i am getting back is just the first level:
[
{
"Channel": "online",
"Credit Score": "20000"
}
]
what am i missing here?