0

I have the following response in JSON from Youtube Data API

{
 "kind": "youtube#channelListResponse",
 "etag": "\"0KG1mRN7bm3nResDPKHQZpg5-do/B7stMlWJTBpmW2q34yWKIzz8fF8\"",
 "pageInfo": {
  "totalResults": 1,
  "resultsPerPage": 1
 },
 "items": [
  {
   "kind": "youtube#channel",
   "etag": "\"0KG1mRN7bm3nResDPKHQZpg5-do/vV2FFZUI5inz53NuQDJMTs3tdQk\"",
   "id": "UCwy6X3JB24VTsDFqMwdO5Jg",
   "contentDetails": {
    "relatedPlaylists": {
     "uploads": "UUwy6X3JB24VTsDFqMwdO5Jg"
    },
    "googlePlusUserId": "114467711950028252332"
   }
  }
 ]
}

I'm trying to turn it into an object using JSON.parse but doing so gives me this.

{ kind: 'youtube#channelListResponse',
  etag: '"0KG1mRN7bm3nResDPKHQZpg5-do/B7stMlWJTBpmW2q34yWKIzz8fF8"',
  pageInfo: { totalResults: 1, resultsPerPage: 1 },
  items: 
   [ { kind: 'youtube#channel',
       etag: '"0KG1mRN7bm3nResDPKHQZpg5-do/vV2FFZUI5inz53NuQDJMTs3tdQk"',
       id: 'UCwy6X3JB24VTsDFqMwdO5Jg',
       contentDetails: [Object] } ] }

How can I turn the value of contentDetails into a proper object?

Seong Lee
  • 10,314
  • 25
  • 68
  • 106
  • You're just seeing an artifact of your logging system. Chances are the object you parsed is in fine shape. Many logging systems will abbreviate objects below a certain depth to `"[Object object]"`. –  Oct 25 '15 at 11:41
  • It's a proper object, console.log doesn't show deeply nested objects, but shows Object only instead. Use [util.inspect](https://nodejs.org/api/util.html#util_util_inspect_object_options) and set depth to see it – baao Oct 25 '15 at 11:42

3 Answers3

3

It is already a proper object, it is just not output correctly onto the console. Try printing the result of JSON.parse, e.g. res using the following:

console.log(util.inspect(res, { showHidden: true, depth: null }));

See https://nodejs.org/api/util.html#util_util_inspect_object_options

Oleg Sklyar
  • 9,834
  • 6
  • 39
  • 62
0

it's a proper object, You can still access it's properties in normal way. Because console.log doesn't print deep level object so if you want to see it on the log, let convert it into a string. Try object to string script here https://stackoverflow.com/a/5612876

Community
  • 1
  • 1
0

your can use JSON.stringify(parsedObject) to see the full details

Kaicui
  • 3,795
  • 1
  • 15
  • 20