I am trying to get the a Json object from a url using Express:
this is my code:
app.get('/device/:id', (req, res, next) => {
console.log('device: ' + req.params.id + ' Request received');
let parsedContent = JSON.parse(req.query);
//res.status(201).send('success');
});
this my url:
http://localhost:4001/device/1?{"type":"fridge","pcb"=2.4}
I get an error on the parsing line.
Here is the error as requested:
SyntaxError: Unexpected token o in JSON at position 1
at JSON.parse (<anonymous>)
I have also tried this:
app.get('/device/:id', (req, res, next) => {
let query = url.parse(req.url).query;
if( query ) {
let parsedContent = JSON.parse(decodeURIComponent(query));
}
});
With this url:
http://localhost:4001/device/1??type=fridge&pcb=2.4
Still the same issue.