2

I'm using google knowledge Graph Search (kgsearch) api to return Schemas (schema.org) but some nested elements are not recognized as json or I'm missing something...

url = "https://kgsearch.googleapis.com/v1/entities:search";

request.get(url).query({
  key: KEY,
  types: "Person",
  query:"Taylor Swift", //search expression
  limit: 1,
  indent: true

}).end(function(err, response){
  console.log(response.body.itemListElement.detailedDescription);
});

In Google api documentation it should return something like:

  [{"@type": "ItemList",
  "itemListElement": [
    {
      "@type": "EntitySearchResult",
      "result": {
        "@id": "kg:/m/0dl567",
        "name": "Taylor Swift",
        "@type": [
          "Thing",
          "Person"
        ],
        "description": "Singer-songwriter",
        "image": {
          "contentUrl": "https://t1.gstatic.com/images?q=tbn:ANd9GcQmVDAhjhWnN2OWys2ZMO3PGAhupp5tN2LwF_BJmiHgi19hf8Ku",
          "url": "https://en.wikipedia.org/wiki/Taylor_Swift",
          "license": "http://creativecommons.org/licenses/by-sa/2.0"
        },
        "detailedDescription": {
          "articleBody": "Taylor Alison Swift is an American singer-songwriter and actress. Raised in Wyomissing, Pennsylvania, she moved to Nashville, Tennessee, at the age of 14 to pursue a career in country music. ",
          "url": "http://en.wikipedia.org/wiki/Taylor_Swift",
          "license": "https://en.wikipedia.org/wiki/Wikipedia:Text_of_Creative_Commons_Attribution-ShareAlike_3.0_Unported_License"
        },
        "url": "http://taylorswift.com/"
      },
      "resultScore": 896.576599
    }]

But here's what's return by node.js :

[ { '@type': 'EntitySearchResult',
    result: 
     { '@id': 'kg:/m/0576bq',
       name: '2005–06 NHL season',
       '@type': [Object],
       description: 'Sports League Season',
       detailedDescription: [Object] },
    resultScore: 10.426484 } ]

Why does the detailDescription field is not returned as string? When I tried to access it directly it returns 'undefined'.

Thanks!

0cnLaroche
  • 268
  • 1
  • 4
  • 8

1 Answers1

0

It returns a JSON object not string, so that you need JSON.stringify method to print the nested objects in string format. console.log(JSON.stringify(response.body.itemListElement.detailedDescription, null, 4));

Ming L.
  • 391
  • 2
  • 7