API Response parsing in yellow.ai API Node

image

I am trying to parse the JSON response from an external API call and parse, store that in an variable. But getting the follow error.

You can refer to my code for parsing the response.

return new Promise(resolve => {
        let apiResponse = ymLib.args.apiResponse;
        let body;
        if(apiResponse && apiResponse.results){
            let data = JSON.parse(apiResponse);
        }
        // Your logic goes here
        let returnedData = [];
        for(let row in data.results){
            let temp = {};
            temp['Address'] = row.formatted;
            temp['geometry'] = row.geometry;
            console.log(temp);
            returnedData.push(temp);
        }

        resolve(returnedData);
    });                  

Any help is greatly appreciated. It would be great if there is any documentation and best practices for parsing response and displaying as a Text node.

Hey @Vishal_Vishwanathan,

Instead of resolving an array value in API’s Parse Function, Maybe Try resolving an object and store the API Response in an Object Variable?

Great thanks, that seems to work. I want to convert an Array into displaying a list? Is it possible in the yellow.ai docs.

Data looks like this in a “Text Node” [object Object]. What steps can be used to resolve this @Amudhan_S

If you want to display array items in a “Text Node”, then create a function to loop through the array.

Inside the loop, Concat each items to a String Variable.

Resolve the String Variable and print this String Variable in the “Text Node”.

Note:

If you want to see an array or object variable value, then i would suggest you to create a Dummy DB Table with “JSON” column.

Then Insert this array or object variable value into this JSON Column by using Database Insert Node. Once this is done successfully, You can copy paste the JSON in any of your Code Editors like VS Code by saving the File with “.json” extension for better viewing experience.