aacerox/node-rest-client

NRC doesn't parse nested JSON objects

Opened this issue · 1 comments

I have an endpoint that returns a nested JSON object structure. When cURL'ing the endpoint, the data is returned correctly:

~/D/s/n/rest-client ❯❯❯ curl -L https://script.google.com/macros/s/AKfycbx6pXNiHj_D1dQNRPbPCehXO3ZZRlzts8ZO3J2qx_fPU1mpPOQ4/exec
{
"today":"2017-04-18T14:00:00.000Z",
"result":"successfully",
"staff":[
{
"name":"Staff 3",
"events":[
{
"event_type":"On Leave",
"from":"2017-04-17T14:00:00.000Z",
"to":"2017-05-03T13:59:59.999Z"
},
{
"event_type":"On Leave",
"from":"2017-06-04T14:00:00.000Z",
"to":"2017-06-09T13:59:59.999Z"
}
]
},
{
"name":"Staff 10",
"events":[
{
"event_type":"On Leave",
"from":"2017-04-20T14:00:00.000Z",
"to":"2017-04-24T13:59:59.999Z"
}
]
},
{
"name":"Staff 1",
"events":[
{
"event_type":"On Leave",
"from":"2017-04-23T14:00:00.000Z",
"to":"2017-04-24T13:59:59.999Z"
},
{
"event_type":"Working remotely",
"from":"2017-04-30T14:00:00.000Z",
"to":"2017-05-08T13:59:59.999Z"
}
]
}
]
}

but when i log the output from NRC, i get the following JSON payload in the response:

~/D/s/n/rest-client ❯❯❯ node app.js
{ today: '2017-04-18T14:00:00.000Z',
result: 'successfully',
staff:
[ { name: 'Staff 3', events: [Object] },
{ name: 'Staff 10', events: [Object] },
{ name: 'Staff 1', events: [Object] } ] }

Where you can see NRC is just returning the type of the structure rather than the parsed content.

it do parse .. xD you just need to access the object directly

example on centova if i call the api it will give me this as a data

{ type: 'success',
  response:
   { data: { status: [Object], mountpoints: [Object] },
     message: 'Complete' } }

but i know the structure of the json it self

console.log(data.response.data.status);

now i get

{ mount: '/stream',
  sid: 1,
  listenercount: 2,
  genre: 'Unspecified',
  url: 'http://example.com',
  title: 'Sample Stream',
  currentsong: 'fhána  青空のラプソディ   MUSIC AUDIO',
 current
  currentsongstart: 1494357847,
  bitrate: 128,
  sourceconnected: 1,
  sourceip: 'censored',
  codec: 'audio/mpeg',
  directory: { listed: 0, code: 0, message: null },
  displayname: '/stream',
  serverstate: true,
  appstate: { sctrans2: true },
  sourcestate: true,
  reseller: false,
  useserver: 1,
  ipaddress: 'censored',
  port: censored,
  proxy: 0,
  servertype: 'ShoutCast2',
  sourcetype: 'sctrans2' }

now if i call
console.log(data.response.data.status.currentsong);
it should give the current song ...

result: fhána 青空のラプソディ MUSIC AUDIO