I have an JSON data coming back from an API, I want to convert it to an array, but having trouble getting the "timeline" category into the array,
Sample JSON:
[{
"id": 100,
"key1": 310797,
"key2": 807874,
"key3": 24283,
"key4": 180900,
"timeline": {
"createDate": "2021-04-08T22:53:23Z",
"lastChangeDate": "2021-04-27T12:03:57Z"
}
},
{
"id": 101,
"key1": 310797,
"key2": 807875,
"key3": 24284,
"key4": 180903,
"timeline": {
"createDate": "2021-04-04T22:53:23Z",
"lastChangeDate": "2021-04-24T12:02:57Z"
},
{
...
}
]
I am using the follow Javascript to try and parse this to an array
function convertToArray(json) {
var headers = Object.keys(json[0]);
var values = json.map(function(e) {
return headers.map(function(f) {
return e[f]
})
});
values.unshift(headers);
return values
}
This is returning:
[[id, key1, key2, key3, key4, timeline],
[100, 310797, 807874, 24283, 180900, ""],
[101, 310797, 807875, 24284, 180903, ""]]
However the Array I am trying to achieve is:
[[id, key1, key2, key3, key4, createDate, lastChangeDate],
[100, 310797, 807874, 24283, 180900, 2021-04-08T22:53:23Z, 2021-04-27T12:03:57Z],
[101, 310797, 807875, 24284, 180903, 2021-04-04T22:53:23Z, 2021-04-24T12:02:57Z]]
Any assistance with how I can map the "createDate" and "lastChangeDate" into the array would be truly appreciated