I have a nested array, looking like that:
{
"id": 1,
"QUALITY": 91.98,
"TEMPERATURE": 20.5,
"SENSOR_DATE": "2021-09-24T04:53:06.801Z",
"SOURCE_ID": 1,
"SENSOR_NAME": "TD2",
"NEXT_OFFSET": 11931
},
I wanna change this string
"QUALITY": 91.98,
"TEMPERATURE": 20.5,
to this:
{
"data": [
{
"TELEMATICS": {
"QUALITY": 91.98,
"TEMPERATURE": 20.5
},
"SOURCE_ID": "1",
"SENSOR_NAME": "TD2",
"SENSOR__DATETIME": "2021-09-24T04:53:06.801Z"
},
],
"NEXT_OFFSET": 11931
}
I have made many different attempts, but all I could get as a result of this code is:
var telematics = JSON.parse(JSON.stringify(payload, ['QUALITY', 'TEMPERATURE']));
var data = JSON.parse(JSON.stringify(payload, ['SOURCE_ID', 'SENSOR_NAME', 'SENSO$
payload = JSON.parse(JSON.stringify({TELEMATICS: telematics, data}, null, 2));
payload = JSON.stringify({data: payload}, null, 2);
As a result, I get two different objects. I can't combine them into one, with a nested TELEMATICS array:
{
"QUALITY": 91.33,
"TEMPERATURE": 25.7
}
],
"data": [
{
"SOURCE_COMPONENT_ID": 1,
"SENSOR_NAME": "TD2",
"SENSOR_READING_DATETIME": "2021-09-24T04:53:06.801Z"
},