\n too present when writing to binary file

I am trying to write my site’s downtime to the disk with “move binary data” and “write binary file” but when it writes the binary file It outputs "\"\\n\\n07:30 - Status: Offline\"\n08:00 - Status: Offline" instead of "07:30 - Status: Offline" "08:00 - Status: Offline" I can’t find a way to make it not do this and would appreciate guidance.

Hey @cixastra!

Can you share the workflow? I tried it on my end and it works for me. Here’s my sample workflow:

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "fileName": "/PATH/file.txt"
      },
      "name": "Write Binary File",
      "type": "n8n-nodes-base.writeBinaryFile",
      "typeVersion": 1,
      "position": [
        850,
        300
      ],
      "continueOnFail": true
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "value": "harshil"
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "mode": "jsonToBinary",
        "options": {}
      },
      "name": "Move Binary Data",
      "type": "n8n-nodes-base.moveBinaryData",
      "typeVersion": 1,
      "position": [
        650,
        300
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set": {
      "main": [
        [
          {
            "node": "Move Binary Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Move Binary Data": {
      "main": [
        [
          {
            "node": "Write Binary File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Yes, my workflow is here. I don’t know how to fix this.

{
  "name": "Downtime",
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        200,
        460
      ]
    },
    {
      "parameters": {
        "url": "https://svtsa.ga",
        "allowUnauthorizedCerts": true,
        "responseFormat": "string",
        "dataPropertyName": "Site Value",
        "options": {}
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        470,
        540
      ],
      "alwaysOutputData": true,
      "continueOnFail": true
    },
    {
      "parameters": {
        "webhookUri": "",
        "text": "=24 Hour Check in with https://svtsa.ga/"
      },
      "name": "Success Disc Post",
      "type": "n8n-nodes-base.discord",
      "typeVersion": 1,
      "position": [
        1330,
        220
      ]
    },
    {
      "parameters": {
        "webhookUri": "",
        "text": "=<@&845019927538434078> | <@641053974245408788> \nhttps://svtsa.ga is currently down and has experienced the following downtime in the last 24 hours.\n{{$node[\"Set Downtime list\"].json[\"newdowntime\"]}}"
      },
      "name": "Fail Disc Post",
      "type": "n8n-nodes-base.discord",
      "typeVersion": 1,
      "position": [
        1630,
        720
      ]
    },
    {
      "parameters": {
        "triggerTimes": {
          "item": [
            {
              "mode": "custom",
              "cronExpression": "0/30 * * * * "
            }
          ]
        }
      },
      "name": "Cron",
      "type": "n8n-nodes-base.cron",
      "typeVersion": 1,
      "position": [
        200,
        610
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$node[\"HTTP Request\"].json[\"Site Value\"]}}",
              "operation": "contains",
              "value2": "=<script src=\"https://cdn-app.continual.ly/js/embed/continually-embed.latest.min.js\"></script>"
            }
          ]
        }
      },
      "name": "UP / Down",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        640,
        540
      ]
    },
    {
      "parameters": {
        "fileSelector": "/home/cixastra/Documents/timesperday",
        "dataPropertyName": "timesperday"
      },
      "name": "Read Binary Files",
      "type": "n8n-nodes-base.readBinaryFiles",
      "typeVersion": 1,
      "position": [
        810,
        490
      ]
    },
    {
      "parameters": {
        "sourceKey": "timesperday",
        "options": {}
      },
      "name": "Move Binary Data",
      "type": "n8n-nodes-base.moveBinaryData",
      "typeVersion": 1,
      "position": [
        950,
        490
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$node[\"Move Binary Data\"].json[\"timesperday\"]}}",
              "value2": "48"
            }
          ]
        }
      },
      "name": "IF48",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        1090,
        490
      ]
    },
    {
      "parameters": {
        "command": "=expr {{$node[\"Move Binary Data\"].json[\"0\"]}} + 1"
      },
      "name": "+1",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        1350,
        560
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "timesperday",
              "value": "={{$node[\"+1\"].json[\"stdout\"]}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        1530,
        560
      ]
    },
    {
      "parameters": {
        "mode": "jsonToBinary",
        "convertAllData": false,
        "sourceKey": "timesperday",
        "destinationKey": "timesperday",
        "options": {}
      },
      "name": "Move Binary Data1",
      "type": "n8n-nodes-base.moveBinaryData",
      "typeVersion": 1,
      "position": [
        1770,
        500
      ]
    },
    {
      "parameters": {
        "command": "date +%H:%M"
      },
      "name": "Get Time",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        1030,
        720
      ]
    },
    {
      "parameters": {
        "filePath": "/home/cixastra/Documents/downtime",
        "dataPropertyName": "downtime"
      },
      "name": "Read Downtime",
      "type": "n8n-nodes-base.readBinaryFile",
      "typeVersion": 1,
      "position": [
        770,
        720
      ]
    },
    {
      "parameters": {
        "setAllData": false,
        "sourceKey": "downtime",
        "destinationKey": "jsondowntime",
        "options": {}
      },
      "name": "Get Downtime",
      "type": "n8n-nodes-base.moveBinaryData",
      "typeVersion": 1,
      "position": [
        900,
        720
      ]
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "newdowntime",
              "value": "={{$node[\"Get Downtime\"].json[\"jsondowntime\"]}}\n{{$node[\"Get Time\"].json[\"stdout\"]}} - Status: Offline"
            }
          ]
        },
        "options": {}
      },
      "name": "Set Downtime list",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        1170,
        720
      ]
    },
    {
      "parameters": {
        "mode": "jsonToBinary",
        "convertAllData": false,
        "sourceKey": "newdowntime",
        "destinationKey": "downtime",
        "options": {}
      },
      "name": "Convert Downtime",
      "type": "n8n-nodes-base.moveBinaryData",
      "typeVersion": 1,
      "position": [
        1310,
        720
      ]
    },
    {
      "parameters": {
        "fileName": "/home/cixastra/Documents/downtime",
        "dataPropertyName": "downtime"
      },
      "name": "Write downtime to disk",
      "type": "n8n-nodes-base.writeBinaryFile",
      "typeVersion": 1,
      "position": [
        1480,
        720
      ]
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "newdowntime"
            }
          ]
        },
        "options": {}
      },
      "name": "Reset Downtime",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        1530,
        410
      ]
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "timesperday",
              "value": "0"
            }
          ]
        },
        "options": {}
      },
      "name": "Reset Times Per day",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        1350,
        410
      ]
    },
    {
      "parameters": {
        "fileName": "/home/cixastra/Documents/downtime",
        "dataPropertyName": "downtime"
      },
      "name": "Write reset Downtime",
      "type": "n8n-nodes-base.writeBinaryFile",
      "typeVersion": 1,
      "position": [
        1920,
        340
      ]
    },
    {
      "parameters": {
        "fileName": "/home/cixastra/Documents/timesperday",
        "dataPropertyName": "timesperday"
      },
      "name": "Write times per day",
      "type": "n8n-nodes-base.writeBinaryFile",
      "typeVersion": 1,
      "position": [
        1920,
        500
      ]
    },
    {
      "parameters": {
        "mode": "jsonToBinary",
        "convertAllData": false,
        "sourceKey": "newdowntime",
        "destinationKey": "downtime",
        "options": {}
      },
      "name": "Convert Downtime1",
      "type": "n8n-nodes-base.moveBinaryData",
      "typeVersion": 1,
      "position": [
        1760,
        340
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$node[\"HTTP Request\"].json[\"Site Value\"]}}",
              "operation": "contains",
              "value2": "=<script src=\"https://cdn-app.continual.ly/js/embed/continually-embed.latest.min.js\"></script>"
            }
          ]
        }
      },
      "name": "UP / Down1",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        1210,
        340
      ]
    }
  ],
  "connections": {
    "HTTP Request": {
      "main": [
        [
          {
            "node": "UP / Down",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Cron": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Start": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "UP / Down": {
      "main": [
        [
          {
            "node": "Read Binary Files",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Read Downtime",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Binary Files": {
      "main": [
        [
          {
            "node": "Move Binary Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Move Binary Data": {
      "main": [
        [
          {
            "node": "IF48",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF48": {
      "main": [
        [
          {
            "node": "UP / Down1",
            "type": "main",
            "index": 0
          },
          {
            "node": "Reset Times Per day",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "+1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "+1": {
      "main": [
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set": {
      "main": [
        [
          {
            "node": "Move Binary Data1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Move Binary Data1": {
      "main": [
        [
          {
            "node": "Write times per day",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Time": {
      "main": [
        [
          {
            "node": "Set Downtime list",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Downtime": {
      "main": [
        [
          {
            "node": "Get Downtime",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Downtime": {
      "main": [
        [
          {
            "node": "Get Time",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Downtime list": {
      "main": [
        [
          {
            "node": "Convert Downtime",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert Downtime": {
      "main": [
        [
          {
            "node": "Write downtime to disk",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write downtime to disk": {
      "main": [
        [
          {
            "node": "Fail Disc Post",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Reset Downtime": {
      "main": [
        [
          {
            "node": "Move Binary Data1",
            "type": "main",
            "index": 0
          },
          {
            "node": "Convert Downtime1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Reset Times Per day": {
      "main": [
        [
          {
            "node": "Reset Downtime",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert Downtime1": {
      "main": [
        [
          {
            "node": "Write reset Downtime",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fail Disc Post": {
      "main": [
        [
          {
            "node": "+1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "UP / Down1": {
      "main": [
        [
          {
            "node": "Success Disc Post",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "timezone": "America/Chicago",
    "saveExecutionProgress": "DEFAULT"
  },
  "id": "1"
}

Thanks for sharing the workflow. Unfortunately, I can’t replicate the issue since I don’t know what information is present in the file that you’re reading.

In one of my workflows, I am using the following Function node to generate the binary data. Maybe this might help

{
  "nodes": [
    {
      "parameters": {
        "functionCode": "return items.map(item => {\n  return {\n    json: {},\n    binary: {\n      data: {\n\t\tdata: Buffer.from(JSON.stringify(item.json, null, '\\t')).toString('base64'),\n\t    mimeType: 'application/json',\n\t  }\n    }\n  }\n});"
      },
      "name": "JSON to Binary",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        850,
        300
      ],
      "continueOnFail": true
    }
  ],
  "connections": {}
}

The code is getting the items from the previous node and converting it to binary data.

I am converting a string for my downtime. Basically it generates a string for the downtime based on the old downtime then writes it to the disk. But I get the \n things when it is only supposed to be words.

I have decided to go with google sheets to store the data instead :slight_smile:

1 Like