Saturday 10 June 2017

return json with nested array for data and heading in nodejs express

I have a nodejs api that returns json formatted like this..

[

{
    "id" : "1",
    "tstamp": "2017-06-01T00:00:00.000Z",
    "dmemberprofiles","48400"
    "dgroupprofiles","4800"
    "msclprofiles","400"
},
{
    "id" : "2",
    "tstamp" : "2017-06-02T00:00:00.000Z",
    "dmemberprofiles","48700"
    "dgroupprofiles","4900"
    "msclprofiles","410
}

]

How do i make nodejs retun the json looking like... {

"header": [
    "id",
    "tstamp",
    "dmemberprofiles",
    "dgroupprofiles",
    "msclprofiles"
],
"data": [
    {
        "id" : "1",
        "tstamp" : "2017-06-01T00:00:00.000Z",
        "dmemberprofiles","48400"
        "dgroupprofiles","4800"
        "msclprofiles","400"
    },
    {
        "id" : "2",
        "tstamp" : "2017-06-02T00:00:00.000Z",
        "dmemberprofiles","48700"
        "dgroupprofiles","4900"
        "msclprofiles","410
    }           
]

}

I've looked around for other examples but haven't found solution for nodejs specific.

Thank you-



via user3442693

No comments:

Post a Comment