JSFiddle - React, Tailwind, and code Playground
JavaScript
// Part 1
var res_string = '[{"deviceId": "9092eab10f4","name": "temperature","timestamp": "2017-06-13T13:19:59.673Z","value": 21.5},{"deviceId": "9092eab10f4","name": "temperature","timestamp": "2017-06-13T13:19:59.673Z","value": 21.5}]'
console.log("Start - Part 1");
var new_res_from_string = {"data": JSON.parse(res_string)}
console.log(new_res_from_string);
console.log("End - Part 1");
// Part 2
console.log("Start - Part 2");
var res_arr = [
{
"deviceId": "9092eab10f4",
"name": "temperature",
"timestamp": "2017-06-13T13:19:59.673Z",
"value": 21.5
},
{
"deviceId": "9092eab10f4",
"name": "temperature",
"timestamp": "2017-06-13T13:19:59.673Z",
"value": 21.5
}
];
var new_res = { "data" : res_arr }
console.log(new_res);
console.log("End - Part 2");