# File that looks fine but may be encoded wrong

**URL:** <https://discourse.nodered.org/t/file-that-looks-fine-but-may-be-encoded-wrong/61732>\
**Category:** General\
**Created:** [24 April 2022 20:51 UTC](https://discourse.nodered.org/t/file-that-looks-fine-but-may-be-encoded-wrong/61732 "2022-04-24T20:51:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [24 April 2022 20:51 UTC](https://discourse.nodered.org/t/file-that-looks-fine-but-may-be-encoded-wrong/61732/1 "2022-04-24T20:51:21Z")

</div>

OS: macOS 12.2.1  
Node-RED version: v2.2.2  
Node.js version: v14.16.0  
Darwin 21.3.0 x64 LE  
Dashboard version 3.1.3 started at /ui

So I have a program creating a CSV file. I need to change the order of the items and rename some of the column headers in order to import it into another program.

When I read the file in it looks fine in the debug panel but trying to convert a string `"$14.35"` I remove the `$` and then try a `parseFloat` and get a NaN.

After spending (way) to much time on this, I know my function code is correct so I used the `file-in` node to read the file (a single utf8 string)

```auto
"status","Receipt Date","Vendor","Category","Payment Type","Sales Tax","Amount","Tax Category","Purpose","Created Date","Modified Date","Reimburse"
"","2022-04-18","Home Depot","Garden","Visa Card","$1.65","$56.06","No Form:Non-deductible","Personal","2022-04-24 09:53:28","2022-04-24 10:32:40",""
"","2022-04-20","Stop&Shop","Grocery Store","Visa Card","$0.00","$128.64","No Form:Non-deductible","Personal","2022-04-24 10:00:07","2022-04-24 10:26:13",""

```

and sent the output to a `file-out` node (encoding default) and when I edit the new file this is what I see:

```auto
��"status","Receipt Date","Vendor","Category","Payment Type","Sales Tax","Amount","Tax Category","Purpose","Created Date","Modified Date","Reimburse"
"","2022-04-18","Home Depot","Garden","Visa Card","$1.65","$56.06","No Form:Non-deductible","Personal","2022-04-24 09:53:28","2022-04-24 10:32:40",""
"","2022-04-20","Stop&Shop","Grocery Store","Visa Card","$0.00","$128.64","No Form:Non-deductible","Personal","2022-04-24 10:00:07","2022-04-24 10:26:13",""

```

In addition as I'm entering the info in this post, this is what I see:

 ![Screen Shot 2022-04-24 at 4.47.48 PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/f/ffec1404e0fcca4756133eb88d3f956c81879be5.png)

Any ideas?

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [24 April 2022 21:46 UTC](https://discourse.nodered.org/t/file-that-looks-fine-but-may-be-encoded-wrong/61732/2 "2022-04-24T21:46:29Z")

</div>

Is it possible your file is in utf32 (= Unicode ?) format?

I'm playing with a Raspberry Pi not a Mac. if I put your data into a file and convert it with

```auto
iconv -f utf8 -t utf32 foo > foobar

```

Then read foobar into Node-red and save it to a new file it looks like this

 ![Untitled 2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/9/591aa0890dab2ba720aefd9037ba1eebb662033c.jpeg)

and in vi it looks like this

 ![Untitled 3](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/9/1926e0ea787fe68ad7ad4b6c3e6672b84735ae5e.jpeg)

Edit

```auto
pi@ZeroTwoTwo:~ $ file -i foo foobar
foo: application/csv; charset=us-ascii
foobar: application/csv; charset=utf-32le

```

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [25 April 2022 00:25 UTC](https://discourse.nodered.org/t/file-that-looks-fine-but-may-be-encoded-wrong/61732/3 "2022-04-25T00:25:31Z")

</div>

@jbudd

> pi@ZeroTwoTwo:~ $ file -i foo foobar

Oh, that's was the key!! I did it on my mac with out the `-i` and got this:

```auto
Paul@PaulsM1 Brother % file BR_export2.csv output1.csv
BR_export2.csv: Unicode text, UTF-16, little-endian text
output1.csv: data

```

so in the `file-in` node I set  
`Output: 'a single utf8 string'`  
`Encoding: 'utf-16le'`  
and it is working!!

Thank you very much!

---

<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:** [9 May 2022 00:25 UTC](https://discourse.nodered.org/t/file-that-looks-fine-but-may-be-encoded-wrong/61732/4 "2022-05-09T00:25:33Z")

</div>

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