I am using Node to INSERT JSON to MySQL, using Node.js
This works fine, until I have nested values.
Example of my JSON is here:
var result2 = [{
"id": 89304,
"employeeDetails": {
"id": 102524,
"version": 9
}
}, {
"id": 89305,
"employeeDetails": {
"id": 102522,
"version": 99
}
}];
Note: I am using the above for testing, as further on I want to call API requests in JSON and return them.
This is how I am sending it to MySQL using Node.js:
var query = connection.query('INSERT INTO employees SET ?', result2,
function(error, results, fields) {
if (error) throw error;
});
Without nesting, this is working fine, however the nested employeeDetails gives me the following error:
Error: ER_BAD_FIELD_ERROR: Unknown column 'employeeDetails' in 'field list'
My current table format is:
- Field: "userID", INT
- Field: "id", INT
- Field: "version", INT