Im stuck with the following problem:
I am fetching a json object from my nodejs backend that is a result of the following MYSQL operation
app.get('/get_events/:playgroundId', cors(), function(req,res){
var playgroundId = req.params.playgroundId;
var sql = "SELECT date as date, CONCAT('[',GROUP_CONCAT(JSON_OBJECT('id', event_id,'time', time,'admin_id', admin_id,'playground_id', playground_id,'event_name', event_name,'description', description,'mode', mode,'type', type,'members', members,'waiting', waiting,'invited', invited)),']') AS list FROM xxx.events where playground_id = '"+playgroundId+"' GROUP BY DATE(date) ORDER BY DATE(date)";
pool.query(sql, function(err, results) {
if(err) {
console.log(err)
return res.send(err)
} else {
return res.json({
data: results
})
}
});
});
On the client side (which is a react app) im using the following fetch:
fetch(`${global.x}/get_events/${playgroundId}`)
.then((res) => res.json())
.then((res) => {
const data = res.data
return data
}).catch((error) => {
//console.log(error)
});
the whole thing basically return a grouped by date json response about events that i got in the database. The final data looks like this:
Array [ Object { "date": "2021-03-17T14:52:18.000Z", "list": "[{"id": "cd66d921-8688-11eb-909e-06a351dd0cca", "mode": "Public", "time": "2021-03-16 19:52:18.000000", "type": "Game", "invited": ["ucLYuwevW5f2uTjdCZpVLBay6kq1"], "members": ["ucLYuwevW5f2uTjdCZpVLBay6kq1"], "waiting": ["ucLYuwevW5f2uTjdCZpVLBay6kq1"], "admin_id": "ucLYuwevW5f2uTjdCZpVLBay6kq1", "event_name": "Ttt", "description": "Vvv", "playground_id": "a32bb687-7ae3-11eb-909e-06a351dd0cca"},{"id": "e2ecc0e4-868a-11eb-909e-06a351dd0cca", "mode": "Public", "time": "2021-03-16 21:07:06.000000", "type": "Game", "invited": ["ucLYuwevW5f2uTjdCZpVLBay6kq1"], "members": ["ucLYuwevW5f2uTjdCZpVLBay6kq1"], "waiting": ["ucLYuwevW5f2uTjdCZpVLBay6kq1"], "admin_id": "ucLYuwevW5f2uTjdCZpVLBay6kq1", "event_name": "Tt", "description": "Ggg", "playground_id": "a32bb687-7ae3-11eb-909e-06a351dd0cca"},{"id": "eed0ee4c-8688-11eb-909e-06a351dd0cca", "mode": "Public", "time": "2021-03-16 19:52:18.000000", "type": "Game", "invited": ["ucLYuwevW5f2uTjdCZpVLBay6kq1"], "members": ["ucLYuwevW5f2uTjdCZpVLBay6kq1"], "waiting": ["ucLYuwe]", }, ]
If i just have 2 events in the DB, the string is properly closed and there is no error. But once I have more than 2 events in there, it seems that the string becomes too long or something and just ends abruptly without proper escapes.
I am not sure whether there is a limit on characters coming from the DB or whether is a json parsing part on the client side.
The error I get in the terminal: SyntaxError: JSON Parse error: Unterminated string
If anybody had similar issues, could you please help.
Thank you!