I am new to Express and I wonder whether I can parse some property before sending the response to the frontend. The response would be an array of objects. In each object there are properties that includes JSON objects which are stringified. I want to parse them before sending them to the frontend.
Would I iterate through the response and use JSON.parse() on all properties which are stringified in the backend or would I have to handle them in my frontend?
Here is my code:
router.get('/posts', function (req, res) {
db.query(
'select * from posts;',
[10*(req.params.page || 0)],
(error, results) => {
if (error) {
console.log(error);
res.status(500).json({status: 'error'});
} else {
res.status(200).json(results);
}
}
);
});