Quiero enviar una respuesta como un diccionario como este:
{ "id": 5928101, "category": "animal welfare", "organizer": "Adam", "title": "Cat Cabaret", "description": "Yay felines!", "location": "Meow Town", "date": "2019-01-03T21:54:00.000Z", "time": "2:00", }Pero estoy usando el siguiente código, lo que da como resultado una matriz
var ress = JSON.stringify(sqlResults) console.log('response json:' + ress) res.send(ress)La matriz resultante tiene corchetes [] como este:
[ { "id": 5928101, "category": "animal welfare", "organizer": "Adam", "title": "Cat Cabaret", "description": "Yay felines!", "location": "Meow Town", "date": "2019-01-03T21:54:00.000Z", "time": "2:00", } ]¿Cómo puedo enviar el resultado sin un tercer paréntesis?
Si devuelve el primer elemento de su matriz sqlResults , debería obtener el resultado que desea.
También debería poder usar res.json(dict) para enviar su resultado al cliente.
sqlResults = [ { "id": 5928101, "category": "animal welfare", "organizer": "Adam", "title": "Cat Cabaret", "description": "Yay felines!", "location": "Meow Town", "date": "2019-01-03T21:54:00.000Z", "time": "2:00", } ]; const dict = sqlResults[0]; var ress = JSON.stringify(dict, null, 2) console.log('response json:' + ress) // You can then send using res.send(ress); // Or simply res.json(dict);