PARSE JSON from ChatGPT and populate Google Sheets

Hi all :slight_smile:
Hope you can help.
So I am exporting 5 comments from ChatGPT in JSON format, then want to parse it and loop through a Google sheet to add each comment in a new row. I’m so stuck, dunno what to do, found some code for the code block but dont think it’s right lol
Screenshots attached
Thanks :slight_smile:

Hello @KyleBehrend, before the “Insert row” action, create a new “Code” piece and add this:

(note element_number is the index of the loop, not the actual element)

Then, as the code put this:

export const code = async (inputs) => {
    const all_items = inputs.all_items;
    const element_number = inputs.element_number

    var index = [];

    for (var x in all_items) {

    index.sort(function (a, b) {    
        return a == b ? 0 : (a > b ? 1 : -1); 

    return all_items[index[element_number-1]];

Then you can use this action’s output as your input for the Google Sheets action. Not the best solution, but might work.

1 Like

Thanks @PFernandez98 that should solve your problem @KyleBehrend , but if you want to fix it without the code just modify your ask GPT prompt, add this to the end of it
Put results in an array of strings and not an object

both solutions should work, cheers.

Thanks for the reply. I now get the output like this but don’t know what to do next?
CleanShot 2023-12-28 at 07.42.33

Now test the code step, and then test the flow

Thanks, tried that but the code comes out like this

Then the loop just adds it all in google sheets like this

@Abdul can you help please :slight_smile:

Hi there @KyleBehrend export the flow and post it here, I will give it a check asap.

I think you are using the code output in the google sheets step which is inside the loop, instead you should test the loop and use the sample data returned from that.