Split comma-separated values and send to different rows in Google Sheets

Hi!
I’m really enjoying building with n8n!

I’m stuck in the following:

I’m trying to split the string in the ‘text’ section of the JSON and send each comma-separated value to different rows in a Google Sheets document.

I tried with the ‘list’ node but getting an error: ‘ERROR: The provided field 'text' is not an array

Sample data:

[
{
"channel_id": "C0439RQBTM1",
"user_id": "U03A1ND0FJS",
"api_app_id": "A04343Y0M8E",
"is_enterprise_install": "false",
"text": "typescript developer, javascript developer, rust developer, nodejs",
}
]

Thanks beforehand.

Hey @Mike_M,

You could split the field by using the .split() option, So something like {{ $json['text'].split(',') }} would split the text field on the , and give you an array.

1 Like

Hey @Jon, thanks for your quick reply!

I added a function node with the code you provided, but now I’m getting the following error:

ERROR: Cannot read properties of undefined (reading ‘every’) [Line 867]
Stack

TypeError: Cannot read properties of undefined (reading 'every')
    at Object.normalizeItems (/usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/src/NodeExecuteFunctions.js:867:23)
    at Object.execute (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Function/Function.node.js:97:34)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Workflow.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/src/Workflow.js:598:28)
    at async /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/src/WorkflowExecute.js:557:53

Hi @Mike_M,

I think @Jon is referring to a previous step to treat the data as follows:

:wink:

1 Like

You got it @martinhache, Nice work :slight_smile:

Oh ok, thanks a lot!

1 Like

I Tried and it works thankyou

Andrew
CAO OMGGamer

I learn new things from you today. Thank you!