I can store a value in a JSON data with one object into MySQL data base, like this:
var data = '{"sensorvalue":"96"}'
const jsdata = JSON.parse(data);
connection.query("INSERT INTO `nodes`(`sensorvalue`) VALUES ('"+jsdata.sensorvalue+"')", (err, res) => {
console.log("counter record inserted");
});
The output:
id | sensorvalue |
---|---|
1 | 96 |
However, I want to store values in a JSON data with two or more objects, like this:
var data = '[{"sensorvalue":"96"},{"sensorvalue":"98"}]'
But, it stores it as a undefined
in row in table.
The expected output:
id | sensorvalue |
---|---|
1 | 96 |
2 | 98 |
I have seen this questionbefore but I don't know how this could help me because in that question is about array of arrays not a JSON data with multiple objects. How could I solve this, please?