# Parse cvs file that number of raw different in some column

**URL:** https://discourse.nodered.org/t/parse-cvs-file-that-number-of-raw-different-in-some-column/81962
**Category:** General
**Created:** [12 October 2023 09:24 UTC](https://discourse.nodered.org/t/parse-cvs-file-that-number-of-raw-different-in-some-column/81962 "2023-10-12T09:24:16Z")
**Posts on this page:** 18
**Page:** 1

<div class="post-metadata">

### Author: ![okircali](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/okircali/32/79791_2.png) [@okircali](https://discourse.nodered.org/u/okircali)
#### Post date: [12 October 2023 09:24 UTC](https://discourse.nodered.org/t/parse-cvs-file-that-number-of-raw-different-in-some-column/81962/1 "2023-10-12T09:24:16Z")

</div>

Hello, I have a cvs file that have more than one column in a one raw. I want to get the extra columns as an array. However, I just get 1st data of the extra columns in the output of the csv node.

For instance, In the below example I want to get 3 objects , that the object 1 has an array size of 4 , object 2 has array size of 3...

 ![resim](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/9/4916fbe5248e2ee534860c790b142c562770b47a.png)

Do you have a suggestion?

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [12 October 2023 12:29 UTC](https://discourse.nodered.org/t/parse-cvs-file-that-number-of-raw-different-in-some-column/81962/2 "2023-10-12T12:29:19Z")

</div>

Show us an example of what is in the csv file please.  
Copy/paste some of the data, not screenshot.

---

<div class="post-metadata">

### Author: ![okircali](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/okircali/32/79791_2.png) [@okircali](https://discourse.nodered.org/u/okircali)
#### Post date: [12 October 2023 12:47 UTC](https://discourse.nodered.org/t/parse-cvs-file-that-number-of-raw-different-in-some-column/81962/3 "2023-10-12T12:47:50Z")

</div>

Here is one example

| 1 | ŞRJ/2311 | GIOev - WOW İstanbul Hotel | HALKA\_ACIK | GIOEV | GİOEV ŞARJ İSTASYONLARI İŞLETMELERİ ANONİM ŞİRKETİ | Yeşilköy Mahallesi Atatürk Caddesi No:15/1 Bakırköy / İSTANBUL | Soket No | Soket Tipi | Soket Türü | Soket Gücü (kW) |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| | | | | | | | SKT/4245 | DC | DC\_CCS | 300 |
| | | | | | | | SKT/4246 | DC | DC\_CCS | 300 |
| | | | | | | | SKT/4250 | AC | AC\_TYPE2 | 22 |
| 2 | ŞRJ/2312 | GIOev - Antalya - Manavgat | HALKA\_ACIK | GIOEV | GİOEV ŞARJ İSTASYONLARI İŞLETMELERİ ANONİM ŞİRKETİ | Ilıca Mahallesi Antalya Bulvarı Caddesi No:56 Manavgat / ANTALYA | Soket No | Soket Tipi | Soket Türü | Soket Gücü (kW) |
| | | | | | | | SKT/4247 | DC | DC\_CCS | 300 |
| | | | | | | | SKT/4248 | DC | DC\_CCS | 300 |

---

<div class="post-metadata">

### Author: ![okircali](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/okircali/32/79791_2.png) [@okircali](https://discourse.nodered.org/u/okircali)
#### Post date: [12 October 2023 12:48 UTC](https://discourse.nodered.org/t/parse-cvs-file-that-number-of-raw-different-in-some-column/81962/4 "2023-10-12T12:48:54Z")

</div>

It does not pasted in a good format. Here is how it seen on excel;

 ![resim](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/1/11b12a7d6776ab2d553c553e9d5ad4262af33506.png)

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [12 October 2023 12:52 UTC](https://discourse.nodered.org/t/parse-cvs-file-that-number-of-raw-different-in-some-column/81962/5 "2023-10-12T12:52:51Z")

</div>

We need to see it as csv data. So numbers and text interposed with commas.

---

<div class="post-metadata">

### Author: ![okircali](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/okircali/32/79791_2.png) [@okircali](https://discourse.nodered.org/u/okircali)
#### Post date: [12 October 2023 12:58 UTC](https://discourse.nodered.org/t/parse-cvs-file-that-number-of-raw-different-in-some-column/81962/6 "2023-10-12T12:58:36Z")

</div>

I cannot add it as csv here since It is not allowed. Only below formats are available. Let me know How I can send to you.

![resim](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/f/afbdf913128e58f5a0a8229be68680d0b9848d10.png)

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [12 October 2023 13:04 UTC](https://discourse.nodered.org/t/parse-cvs-file-that-number-of-raw-different-in-some-column/81962/7 "2023-10-12T13:04:35Z")

</div>

Open the file with a text viewer and copy/paste the first few lines here.

---

<div class="post-metadata">

### Author: ![okircali](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/okircali/32/79791_2.png) [@okircali](https://discourse.nodered.org/u/okircali)
#### Post date: [12 October 2023 13:17 UTC](https://discourse.nodered.org/t/parse-cvs-file-that-number-of-raw-different-in-some-column/81962/8 "2023-10-12T13:17:37Z")

</div>

```auto
1,ŞRJ/2311,GIOev - WOW İstanbul Hotel,HALKA_ACIK,GIOEV,GİOEV ŞARJ İSTASYONLARI İŞLETMELERİ ANONİM ŞİRKETİ,Yeşilköy Mahallesi Atatürk Caddesi No:15/1 Bakırköy / İSTANBUL,Soket No,Soket Tipi,Soket Türü,Soket Gücü (kW)
,,,,,,,SKT/4245,DC,DC_CCS,300
,,,,,,,SKT/4246,DC,DC_CCS,300
,,,,,,,SKT/4250,AC,AC_TYPE2,22
2,ŞRJ/2312,GIOev - Antalya - Manavgat,HALKA_ACIK,GIOEV,GİOEV ŞARJ İSTASYONLARI İŞLETMELERİ ANONİM ŞİRKETİ,Ilıca Mahallesi Antalya Bulvarı Caddesi No:56 Manavgat / ANTALYA,Soket No,Soket Tipi,Soket Türü,Soket Gücü (kW)
,,,,,,,SKT/4247,DC,DC_CCS,300
,,,,,,,SKT/4248,DC,DC_CCS,300

```

Admin edit. Added backticks around text for easier copying.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [12 October 2023 13:40 UTC](https://discourse.nodered.org/t/parse-cvs-file-that-number-of-raw-different-in-some-column/81962/9 "2023-10-12T13:40:32Z")

</div>

Feeding that into a csv node gives you all the data as an array of objects, then you can adjust the data to get what you want.  
The flow below gives

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/5/15e46b5282784f8662b7b9af66cf127e6e2438c7.png)

```auto
[{"id":"4d7b7feca8506049","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"\"1,ŞRJ/2311,GIOev - WOW İstanbul Hotel,HALKA_ACIK,GIOEV,GİOEV ŞARJ İSTASYONLARI İŞLETMELERİ ANONİM ŞİRKETİ,Yeşilköy Mahallesi Atatürk Caddesi No:15/1 Bakırköy / İSTANBUL,Soket No,Soket Tipi,Soket Türü,Soket Gücü (kW)\\n,,,,,,,SKT/4245,DC,DC_CCS,300\\n,,,,,,,SKT/4246,DC,DC_CCS,300\\n,,,,,,,SKT/4250,AC,AC_TYPE2,22 2,ŞRJ/2312,GIOev - Antalya - Manavgat,HALKA_ACIK,GIOEV,GİOEV ŞARJ İSTASYONLARI İŞLETMELERİ ANONİM ŞİRKETİ,Ilıca Mahallesi Antalya Bulvarı Caddesi No:56 Manavgat / ANTALYA,Soket No,Soket Tipi,Soket Türü,Soket Gücü (kW)\\n,,,,,,,SKT/4247,DC,DC_CCS,300\\n,,,,,,,SKT/4248,DC,DC_CCS,300\"","payloadType":"json","x":190,"y":2240,"wires":[["08c9647e62873ea7"]]},{"id":"52da5cd3580a619a","type":"debug","z":"bdd7be38.d3b55","name":"debug 101","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":510,"y":2240,"wires":[]},{"id":"08c9647e62873ea7","type":"csv","z":"bdd7be38.d3b55","name":"","sep":",","hdrin":"","hdrout":"none","multi":"mult","ret":"\\n","temp":"","skip":"0","strings":true,"include_empty_strings":true,"include_null_values":true,"x":340,"y":2240,"wires":[["52da5cd3580a619a"]]}]

```

---

<div class="post-metadata">

### Author: ![okircali](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/okircali/32/79791_2.png) [@okircali](https://discourse.nodered.org/u/okircali)
#### Post date: [12 October 2023 15:06 UTC](https://discourse.nodered.org/t/parse-cvs-file-that-number-of-raw-different-in-some-column/81962/10 "2023-10-12T15:06:19Z")

</div>

Can we convert it as 2 raw --\> 2 object, 2 object have the last 3 raws as array?

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [12 October 2023 15:18 UTC](https://discourse.nodered.org/t/parse-cvs-file-that-number-of-raw-different-in-some-column/81962/11 "2023-10-12T15:18:19Z")

</div>

For the example posted, show us _exactly_ what form you want the data. Don't use words, show us the what the data should look like. Only then will we know we have correctly interpreted your requirement.

---

<div class="post-metadata">

### Author: ![okircali](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/okircali/32/79791_2.png) [@okircali](https://discourse.nodered.org/u/okircali)
#### Post date: [12 October 2023 15:37 UTC](https://discourse.nodered.org/t/parse-cvs-file-that-number-of-raw-different-in-some-column/81962/12 "2023-10-12T15:37:39Z")

</div>

Below form is what I want;

 ![resim](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/3/2316fa1b7d90d252c2f743d6d61adea831e765fe.png)

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [12 October 2023 16:23 UTC](https://discourse.nodered.org/t/parse-cvs-file-that-number-of-raw-different-in-some-column/81962/13 "2023-10-12T16:23:47Z")

</div>

No, you cannot do that directly. You need to get it into the JSON format first and then reshape it.

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [12 October 2023 16:28 UTC](https://discourse.nodered.org/t/parse-cvs-file-that-number-of-raw-different-in-some-column/81962/14 "2023-10-12T16:28:09Z")

</div>

I would just use a function to do the complete thing at this point.

Example

```auto
[{"id":"4d7b7feca8506049","type":"inject","z":"bf569dbfc3bc07ed","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":200,"y":520,"wires":[["781cf45833955428"]]},{"id":"781cf45833955428","type":"template","z":"bf569dbfc3bc07ed","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"1,ŞRJ/2311,GIOev - WOW İstanbul Hotel,HALKA_ACIK,GIOEV,GİOEV ŞARJ İSTASYONLARI İŞLETMELERİ ANONİM ŞİRKETİ,Yeşilköy Mahallesi Atatürk Caddesi No:15/1 Bakırköy / İSTANBUL,Soket No,Soket Tipi,Soket Türü,Soket Gücü (kW)\n,,,,,,,SKT/4245,DC,DC_CCS,300\n,,,,,,,SKT/4246,DC,DC_CCS,300\n,,,,,,,SKT/4250,AC,AC_TYPE2,22\n2,ŞRJ/2312,GIOev - Antalya - Manavgat,HALKA_ACIK,GIOEV,GİOEV ŞARJ İSTASYONLARI İŞLETMELERİ ANONİM ŞİRKETİ,Ilıca Mahallesi Antalya Bulvarı Caddesi No:56 Manavgat / ANTALYA,Soket No,Soket Tipi,Soket Türü,Soket Gücü (kW)\n,,,,,,,SKT/4247,DC,DC_CCS,300\n,,,,,,,SKT/4248,DC,DC_CCS,300","output":"str","x":160,"y":560,"wires":[["4003aa5b7e7c1745"]]},{"id":"4003aa5b7e7c1745","type":"function","z":"bf569dbfc3bc07ed","name":"function 64","func":"const output = [];\nlet rindex = 0;\nconst rows = msg.payload.split(\"\\n\");\nrows.forEach(row =>{\n let parts = row.split(\",\");\n if (parts[0] != \"\"){\n output[rindex] = parts.slice(0,7);\n output[rindex].push(parts.slice(7,11));\n rindex++;\n }else{\n parts[10] = parseFloat(parts[10]);\n output[rindex - 1].push(parts.slice(7,11));\n }\n})\nmsg.payload = output;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":310,"y":620,"wires":[["52da5cd3580a619a"]]},{"id":"52da5cd3580a619a","type":"debug","z":"bf569dbfc3bc07ed","name":"debug 101","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":510,"y":620,"wires":[]}]

```

[edit] Add Parse number.

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [12 October 2023 16:32 UTC](https://discourse.nodered.org/t/parse-cvs-file-that-number-of-raw-different-in-some-column/81962/15 "2023-10-12T16:32:33Z")

</div>

Or something amusing with JSONata in a change node. 🙂

---

<div class="post-metadata">

### Author: ![okircali](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/okircali/32/79791_2.png) [@okircali](https://discourse.nodered.org/u/okircali)
#### Post date: [16 November 2023 08:17 UTC](https://discourse.nodered.org/t/parse-cvs-file-that-number-of-raw-different-in-some-column/81962/17 "2023-11-16T08:17:34Z")

</div>

When I upload the excel file in cvs format, the read node brings me the two parts of 1 column seperately. How can I get them in one object so after seperate I will get the output as above then I can manage to adjust it as I want in a function node.

 ![resim](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/f/1f18e6a04a4ac323450dae7e63a535af26e25931.png)

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [16 November 2023 16:38 UTC](https://discourse.nodered.org/t/parse-cvs-file-that-number-of-raw-different-in-some-column/81962/18 "2023-11-16T16:38:22Z")

</div>

Would appear to imply that there is something wrong in the CSV file.

But without access to the source data, it is hard to know. Maybe look for a CSV checker online and make sure that the file is actually valid CSV as a starting point.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [15 January 2024 16:39 UTC](https://discourse.nodered.org/t/parse-cvs-file-that-number-of-raw-different-in-some-column/81962/19 "2024-01-15T16:39:19Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
