I try to use an AJAX request with datatable, but my JSON has the wrong format. So I try to convert the structure. I have a JSON string as an array of objects like this form:
[
{
"timestamp":"1461308319473",
"id":"1",
"value":"77"
},
{
"timestamp":"1461308458181",
"id":"2",
"value":"99"
}
]
But I need this structure:
{
"data": [
[
"1461308319473",
"1",
"77"
],
[
"1461308458181",
"2",
"99"
]
]
}
How can I convert the arrays? I would like to use datatable with this command:
$("#table")
.dataTable({
"ajax": {
"type": "GET",
"url": "https://url",
"dataSrc": function (jsonData) {
for (var i = 0; i < jsonData.length; i++) {
returnData.push({
'timestamp': moment.unix(jsonData[i].timestamp / 1000).format("DD.MM.YY hh:mm:ss"),
'id': jsonData[i].id,
'value': jsonData[i].value
});
}
return returnData;
},
"columns": [
{ "data": "timestamp" },
{ "data": "id" },
{ "data": "value" }
]
}
});
At moment I get the following error:
Thanks