Hi,
I have a bit of JSON i am trying to parse with NPM Body Parser, Meteor, and Picker; The client sends the following request:
{
“id”:“12345”,
gps:“1234.51,adsf.er2r”,
apikey:“32342”,
timestamp:“2014-06-25T00:00:00.000Z”,
sensordata: {
moisture: “value”,
temp: “degrees-c”,
humidity: “percent”
}
}
And my Meteor code looks like this(for testing):
import { Picker } from ‘meteor/meteorhacks:picker’;
import bodyParser from ‘body-parser’;
Picker.middleware(bodyParser.urlencoded({ extended: false }));
Picker.middleware(bodyParser.json());
const postRoutes = Picker.filter((req, res) => {
return req.method === ‘POST’;
});
postRoutes.route(’/test’, function (params, req, res) {
console.log(req.body.id);
res.end(‘OK’);
});
The problem is, when I console.log, the id, it shows up as undefined. Only when I remove the quotes from the JSON fragment, does it work. So this works:
{
id:“12345”,
gps:“1234.51,adsf.er2r”,
apikey:“32342”,
timestamp:“2014-06-25T00:00:00.000Z”,
sensordata: {
moisture: “value”,
temp: “degrees-c”,
humidity: “percent”
}
}
Can someone explain why the quotes do not work?
thanks,
~A