I have table say TEST(id INT, attribute JSON) in MySQL 5.7
When I try to query the table in Nodejs using mysql package as follows
con.query("select * from TEST where id=?", [req.params.id], function (err, results) {
if (err) throw err;
console.log(results);
});
I get the following output
[
{
"id": 2,
"package": "{\"tag\": \"tag1\", \"item\": \"item1\"}"
}
]
Is there a way to get the package item in the above result as JSON object instead of a string without iterating the array and do JSON.parse to convert string to JSON?
Expected Output
[
{
"id": 2,
"package": {"tag": "tag1",
"item": "item1"}
}
]