I am asking for help with node Function to convert CSV file

Hello community!
I am asking for help with node Function to convert CSV file.
Need to:

  1. Decompose in columns each line with a separator “/”;
  2. Remove blank lines;
  3. The file does not have the first line with the key, so make the number in order (1, 2, 3, …).
    Example CSV file: https://freezi.ru/wp-content/uploads/2020/09/1-1.csv

Something like that would be possible:

{
  "nodes": [
    {
      "parameters": {
        "options": {
          "rawData": false,
          "readAsString": true
        }
      },
      "name": "Spreadsheet File",
      "type": "n8n-nodes-base.spreadsheetFile",
      "typeVersion": 1,
      "position": [
        1300,
        300
      ]
    },
    {
      "parameters": {
        "url": "https://freezi.ru/wp-content/uploads/2020/09/1-1.csv",
        "responseFormat": "string",
        "options": {}
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        700,
        300
      ]
    },
    {
      "parameters": {
        "mode": "jsonToBinary",
        "convertAllData": false,
        "options": {
          "mimeType": "text/csv",
          "useRawData": true
        }
      },
      "name": "Move Binary Data",
      "type": "n8n-nodes-base.moveBinaryData",
      "typeVersion": 1,
      "position": [
        1100,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "items[0].json.data = Array.from(Array(14), (_,i) => i+1) + '\\n' + items[0].json.data.replace(/\\//g, ',').split('\\n').filter(line => !!line.trim()).join('\\n')\n\n\nreturn items;"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        900,
        300
      ]
    }
  ],
  "connections": {
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Move Binary Data": {
      "main": [
        [
          {
            "node": "Spreadsheet File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "Move Binary Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
1 Like

Thank you Jan!
It works great!

Great to hear! Have fun!