var myDataArray = JSON.parse(msg.payload.split(','));
var heading = myDataArray[0];
var latitude = myDataArray[1];
var longitude = myDataArray[2];
var speed = myDataArray[3];
var trip_id = myDataArray[4];
msg.topic = "INSERT INTO `car-data`.`car-data-table` (`heading`,`latitude`, `longitude`, `speed`, `trip_id`) VALUES ("+heading+","+ latitude +", "+longitude+", "+speed+", "+trip_id+")";
return msg;
But I have an Error and do not know what I need to do.
Can you define what you mean by that please, it looks to me as if you are trying to write property values to the database not JSON.
Also if it is JSON to start with (which means it is a string representing a javascript object) then why have you got the JSON node there?
var myDataArray = msg.payload;
var heading = myDataArray.d.heading;
var latitude = myDataArray.d.latitude;
var longitude = myDataArray.d.longitude;
var speed = myDataArray.d.speed;
var trip_id = myDataArray.d.trip_id;
msg.topic = "INSERT INTO `trip` (`trip_id`) VALUES ("+trip_id+")";
msg.topic = "INSERT INTO `location` (`heading`,`latitude`, `longitude`, `speed`) VALUES ("+heading+","+ latitude +", "+longitude+", "+speed+")";
return msg;