this is the JSON object and I need to access the gps-recs: entries. The dash (-) is giving me and error on not defined when I tried to parse:
"recs-count": 139,
"gps-recs": [
{
"RecId": 40020551513,
"City": "New Port Richey",
"Country": "USA",
"County": "PASCO",
"State": "FL",
"Street": "1546 Amaryllis ct.",
"ZipCode": "34655",
"CurrentOdometer": 12161,
"Heading": 0,
"Latitude": 28.181690,
"Longitude": -82.658420,
"SpeedMph": 0,
"SpeedLimitMph": 25,
"Status": "Stopped",
"StatusDuration": "1.05:00:00",
"PrimaryLandmarkName": "Max's home",
"CurrentHardmountEvent": null,
"UtcTimeTag": "2013-11-28T05:23:34",
"UserTimeTag": "2013-11-28T00:23:34",
"UserInfo": {
"UserId": 201274,
"UserNumber": "22",
"UserName": "Max's Car"
}
},
{
"RecId": 40020551610,
"City": "New Port Richey",
"Country": "USA",
"County": "PASCO",
"State": "FL",
"Street": "1546 Amaryllis ct.",
"ZipCode": "34655",
"CurrentOdometer": 12161,
"Heading": 0,
"Latitude": 28.181690,
"Longitude": -82.658410,
This is my code:
var request = require("request");
var options = { method: 'GET',
url: 'URL',
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
var result = JSON.parse(body);
console.log(result);
console.log(Object.keys(result).length);
});
the parse statement I am trying to use to parse the portion inside the gps-recs entry is:
var result = JSON.parse(body).gps-recs;
I am receiving the following error message: ReferenceError: recs is not defined