skip to Main Content

I’m trying to build a web app that can perform a semantic search using natural language and return the answer as a result. Using response.data.results, I am able to see the caption text in the console under semanticSearch->captions->text.

console image

However I can’t figure out what is the syntax to access that info. I tried response.data.results.semanticSearch.captions[0].text but that is giving me an error "TypeError: Cannot read properties of undefined (reading ‘captions’)"

Any advice would be much appreciated.

Thanks!
Kenneth

2

Answers


  1. Chosen as BEST ANSWER

    I was able to use stringify to turn the object to a string, then parsed it accordingly.

        var output = JSON.stringify(response.data.results);                      
        var pos = output.indexOf("text"); 
        var partOutput = output.slice(pos+7,pos+2000);
        var pos2 = partOutput.indexOf(""highlights"");             
        var finalOutput = partOutput.slice(0,pos2-2);              
        console.log(finalOutput);    
    

  2. So, assuming that JSON on your screenshot coming from the log response.data.results, it turns out it that’s an array. You just need to specify the indice like;

    const result = response.data.results[0]; // or 1? whichever you need;
    console.log(semanticSearch.captions[0].text)
    

    log screenshot

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search