Bwizard
Bwizard

Reputation: 1023

Node.js parsing JSON

should be a simple one but I can't find an answer..

I am console logging some parsed Json but it only shows one level and does not show the deeper objects in the log..

{ jsonrpc: '2.0',
  result: 
   [ { marketId: '1.118750017',
       marketName: 'Match Odds',
       marketStartTime: '2015-05-12T15:30:00.000Z',
       totalMatched: 52.32,
       runners: [Object],
       eventType: [Object],
       competition: [Object],
       event: [Object] } ],
  id: 1 }

How do I log and expand on the items showing as objects above. I know they exist but can't print them out to the screen.

code is simply;

var response = JSON.parse(str);
console.log(response);

If I console log str I get all the data in a not very readable format.

Thanks

Upvotes: 1

Views: 98

Answers (2)

Pavel Kolev
Pavel Kolev

Reputation: 111

Try the following: JSON.stringify(response);

Upvotes: 0

Steve Hynding
Steve Hynding

Reputation: 1869

Try using the util.inspect method with these options:

var util = require('util');

console.log(util.inspect(response, {showHidden: false, depth: null}));

Upvotes: 2

Related Questions