# CSV string values containing new lines

**URL:** https://discourse.nodered.org/t/csv-string-values-containing-new-lines/64437
**Category:** General
**Created:** [27 June 2022 23:52 UTC](https://discourse.nodered.org/t/csv-string-values-containing-new-lines/64437 "2022-06-27T23:52:36Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![RobC](https://avatars.discourse-cdn.com/v4/letter/r/e9a140/32.png) [@RobC](https://discourse.nodered.org/u/RobC)
#### Post date: [27 June 2022 23:52 UTC](https://discourse.nodered.org/t/csv-string-values-containing-new-lines/64437/1 "2022-06-27T23:52:36Z")

</div>

Hi all,  
just doing some tests with CSV and I notice that for string object values including commas it will put quotes around the value, but if there is a string containing a new line (e.g.) it doesn't.  
This has some strange effects for things like Excel.

Wondering if this feature could be an addition.

(Example flow - CSV NR v2.1.4 on Windows)

```auto
[
    {
        "id": "7eb16217e25c257f",
        "type": "inject",
        "z": "5c26fd1ddff9dc3b",
        "name": "Sample Object",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "[{\"name1\":\"value1\",\"name2\":\"value,2\",\"name3\":\"value\\n3\"},{\"name1\":\"value1b\",\"name2\":\"value,2b\",\"name3\":\"value\\n\\r3b\"}]",
        "payloadType": "json",
        "x": 290,
        "y": 180,
        "wires": [
            [
                "2a883b09fe1c006c"
            ]
        ]
    },
    {
        "id": "2a883b09fe1c006c",
        "type": "csv",
        "z": "5c26fd1ddff9dc3b",
        "name": "",
        "sep": ",",
        "hdrin": "",
        "hdrout": "all",
        "multi": "one",
        "ret": "\\r\\n",
        "temp": "",
        "skip": "0",
        "strings": true,
        "include_empty_strings": "",
        "include_null_values": "",
        "x": 470,
        "y": 180,
        "wires": [
            [
                "f4bc05a9f2d6bfab",
                "53a47557e2ec91c1"
            ]
        ]
    },
    {
        "id": "f4bc05a9f2d6bfab",
        "type": "debug",
        "z": "5c26fd1ddff9dc3b",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 650,
        "y": 180,
        "wires": []
    },
    {
        "id": "53a47557e2ec91c1",
        "type": "file",
        "z": "5c26fd1ddff9dc3b",
        "name": "write file",
        "filename": "c:\\Temp\\Testcsv.csv",
        "appendNewline": false,
        "createDir": false,
        "overwriteFile": "true",
        "encoding": "none",
        "x": 640,
        "y": 240,
        "wires": [
            []
        ]
    }
] 

```

output is:  
name1,name2,name3  
value1,"value,2",value  
3  
value1b,"value,2b",value

3b

![csv](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/5/f5c983d764c400fc9f0ca2e8aeb6f98bcd48a6dd.png)

if I manually put quotes around the strings with carriage returns, Excel is happy with it:

name1,name2,name3  
value1,"value,2","value  
3"  
value1b,"value,2b","value

3b"

![csv2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/3/b38142efe193238f67c32c3f03d197fcd873c23b.png)

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [28 June 2022 08:50 UTC](https://discourse.nodered.org/t/csv-string-values-containing-new-lines/64437/2 "2022-06-28T08:50:12Z")

</div>

that could indeed be handled more cleanly.

PR raised here [Fix CSV node to handle \n when outputting text fields by dceejay · Pull Request #3716 · node-red/node-red · GitHub](https://github.com/node-red/node-red/pull/3716)

---

<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: [27 August 2022 08:50 UTC](https://discourse.nodered.org/t/csv-string-values-containing-new-lines/64437/3 "2022-08-27T08:50:29Z")

</div>

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