# Get value from file

**URL:** <https://discourse.nodered.org/t/get-value-from-file/63723>\
**Category:** General\
**Created:** [10 June 2022 13:13 UTC](https://discourse.nodered.org/t/get-value-from-file/63723 "2022-06-10T13:13:01Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kundepuu](https://avatars.discourse-cdn.com/v4/letter/k/bcef8e/32.png) [@Kundepuu](https://discourse.nodered.org/u/Kundepuu)\
**Post date:** [10 June 2022 13:13 UTC](https://discourse.nodered.org/t/get-value-from-file/63723/1 "2022-06-10T13:13:01Z")

</div>

I want to read text file to get value.  
I cant figure how I will get it. Trying many way but cant get. In my top flow then I put same data inject node it works OK...  
I cant find right Json/Jsondata converting method from file data  
Forum dont accept .dump file as seen in picture

[tikkualustus.txt](https://discourse.nodered.org/uploads/short-url/qRFPnZ3nxmt2uBLpmLckJfwOrtG.txt) (453 Bytes)

[flows (11).json](https://discourse.nodered.org/uploads/short-url/pw5aGmjIgzjqIcx5uTYlLdPMYJk.json) (3.6 KB)

 ![read file](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/f/efc068d0a6c6e1a1630fe2f9acc7ca6c89ae371d.jpeg)

---

<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:** [10 June 2022 13:25 UTC](https://discourse.nodered.org/t/get-value-from-file/63723/2 "2022-06-10T13:25:09Z")

</div>

The file node outputs a string that is a valid json, you then pass it through a json node to parse it.  
I edited your flow, the inject node now injects a string same as the file node

```auto
[{"id":"545ab7e5afc0cacd","type":"inject","z":"87cdab2ed104ba34","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"tikku1nimi\":\"Kanan koipi 4 kpl\",\"tikku1väri\":\"Punainen\",\"alkulämpö1\":0,\"aloitusaika1\":0,\"lämpösaavutetaan1\":0,\"tikku1pinta\":0,\"tikku1sisä\":0,\"tikku1pintatavoite\":60,\"tikun1loppulämpötila\":0,\"ominaisuuslämpökerroin1\":3490,\"pallo1d\":0.1,\"tiheys1\":1051,\"tikku1sisätavoite\":60,\"tikun1lämmönläpäisykerroin\":4187.826756018863,\"valmistusaika1\":100,\"viive1\":2}","payloadType":"str","x":490,"y":80,"wires":[["dbd2652dd4e809dd","4c9c87fdad876132"]]},{"id":"dbd2652dd4e809dd","type":"json","z":"87cdab2ed104ba34","name":"","property":"payload","action":"","pretty":false,"x":490,"y":120,"wires":[["4c9c87fdad876132"]]},{"id":"4c9c87fdad876132","type":"debug","z":"87cdab2ed104ba34","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":710,"y":120,"wires":[]},{"id":"8e01583ead2f8586","type":"file in","z":"87cdab2ed104ba34","name":"Read Dump_Starterinfo","filename":"C:\\Kundeager\\tikku1alustus.dump","format":"utf8","sendError":true,"x":430,"y":220,"wires":[["5ef3b54e.69ea74"]]},{"id":"13f6fc8ea2e10e1a","type":"inject","z":"87cdab2ed104ba34","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":200,"y":220,"wires":[["8e01583ead2f8586"]]},{"id":"5ef3b54e.69ea74","type":"json","z":"87cdab2ed104ba34","name":"","property":"payload","action":"","pretty":false,"x":590,"y":280,"wires":[["b16a47d91256e86b"]]},{"id":"b16a47d91256e86b","type":"debug","z":"87cdab2ed104ba34","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":710,"y":220,"wires":[]}]

```

P.S It is easier if you up load flow json and small text file as i have done above, then all anyone needs to do is click copy. The way you have shared makes life harder for those trying to help.

---

<div class="post-metadata">

**Author:** ![Kundepuu](https://avatars.discourse-cdn.com/v4/letter/k/bcef8e/32.png) [@Kundepuu](https://discourse.nodered.org/u/Kundepuu)\
**Post date:** [10 June 2022 14:13 UTC](https://discourse.nodered.org/t/get-value-from-file/63723/4 "2022-06-10T14:13:09Z")

</div>

In my post there are flow and text files  
your flow gives error  
10.6.2022 klo 21.09.30[node: c86866be853dfca3](http://127.0.0.1:1880/#)msg : string[40]  
"Unexpected token in JSON at position 0"

---

<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:** [10 June 2022 14:23 UTC](https://discourse.nodered.org/t/get-value-from-file/63723/5 "2022-06-10T14:23:52Z")

</div>

which flow gives error? there where 2

If it's the one with the file node then i suggest it is not reading your file. Put a debug on the file node and show us the output. With out info no one can help you.

Here is an example of you text loaded in a template and works fine

```auto
[{"id":"67a622fa.69e774","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":3420,"wires":[["1806f346.8f2c4d"]]},{"id":"1806f346.8f2c4d","type":"template","z":"bf9e1e33.030598","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"plain","template":"{\n \"tikku1nimi\": \"Kanan koipi 4 kpl\",\n \"tikku1väri\": \"Punainen\",\n \"alkulämpö1\": 0,\n \"aloitusaika1\": 0,\n \"lämpösaavutetaan1\": 0,\n \"tikku1pinta\": 0,\n \"tikku1sisä\": 0,\n \"tikku1pintatavoite\": 60,\n \"tikun1loppulämpötila\": 0,\n \"ominaisuuslämpökerroin1\": 3490,\n \"pallo1d\": 0.1,\n \"tiheys1\": 1051,\n \"tikku1sisätavoite\": 60,\n \"tikun1lämmönläpäisykerroin\": 4187.826756018863,\n \"valmistusaika1\": 100,\n \"viive1\": 2\n}","output":"str","x":240,"y":3460,"wires":[["2f24ad7e.810352"]]},{"id":"2f24ad7e.810352","type":"json","z":"bf9e1e33.030598","name":"","property":"payload","action":"","pretty":false,"x":380,"y":3460,"wires":[["cc65f31c.a638f8"]]},{"id":"cc65f31c.a638f8","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":420,"y":3520,"wires":[]}]

```

also the error says string 40, but your text is longer than 40 chaacters.

---

<div class="post-metadata">

**Author:** ![Kundepuu](https://avatars.discourse-cdn.com/v4/letter/k/bcef8e/32.png) [@Kundepuu](https://discourse.nodered.org/u/Kundepuu)\
**Post date:** [10 June 2022 14:43 UTC](https://discourse.nodered.org/t/get-value-from-file/63723/6 "2022-06-10T14:43:46Z")

</div>

I just want to value "Punainen" from file...  
here is your flow and debug picture

 ![error](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/b/4b128774a5e0a7d1ad2b2b7665b2b128d93a4c0d.jpeg)  
[flows (12).json](https://discourse.nodered.org/uploads/short-url/4m3Gxqt0qDUTnsSXIO1kkleAAhb.json) (1.9 KB)

---

<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:** [10 June 2022 14:48 UTC](https://discourse.nodered.org/t/get-value-from-file/63723/7 "2022-06-10T14:48:59Z")

</div>

Please post your flow using the \</\> button to make life easier.

Your text has an invalid character at position 0. Try deleting the first line and typing it again. There must be some invisible illegal character, often produced by word processors.

---

<div class="post-metadata">

**Author:** ![Kundepuu](https://avatars.discourse-cdn.com/v4/letter/k/bcef8e/32.png) [@Kundepuu](https://discourse.nodered.org/u/Kundepuu)\
**Post date:** [10 June 2022 14:53 UTC](https://discourse.nodered.org/t/get-value-from-file/63723/8 "2022-06-10T14:53:58Z")

</div>

```auto
{
    "tikku1nimi": "Kanan koipi 4 kpl",
    "tikku1väri": "Punainen",
    "alkulämpö1": 0,
    "aloitusaika1": 0,
    "lämpösaavutetaan1": 0,
    "tikku1pinta": 0,
    "tikku1sisä": 0,
    "tikku1pintatavoite": 60,
    "tikun1loppulämpötila": 0,
    "ominaisuuslämpökerroin1": 3490,
    "pallo1d": 0.1,
    "tiheys1": 1051,
    "tikku1sisätavoite": 60,
    "tikun1lämmönläpäisykerroin": 4187.826756018863,
    "valmistusaika1": 100,
    "viive1": 2
}

```

```auto
[
    {
        "id": "87cdab2ed104ba34",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "141647e596bdbcaf",
        "type": "file in",
        "z": "87cdab2ed104ba34",
        "name": "Read Dump_Starterinfo",
        "filename": "C:\\Kundeager\\tikku1alustus.dump",
        "format": "utf8",
        "sendError": true,
        "allProps": false,
        "x": 490,
        "y": 160,
        "wires": [
            [
                "c86866be853dfca3",
                "9ce2c8286e0f8f82"
            ]
        ]
    },
    {
        "id": "78a3440b276c041c",
        "type": "inject",
        "z": "87cdab2ed104ba34",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 260,
        "y": 160,
        "wires": [
            [
                "141647e596bdbcaf"
            ]
        ]
    },
    {
        "id": "c86866be853dfca3",
        "type": "json",
        "z": "87cdab2ed104ba34",
        "name": "",
        "property": "payload",
        "action": "",
        "pretty": false,
        "x": 790,
        "y": 160,
        "wires": [
            [
                "9ce2c8286e0f8f82"
            ]
        ]
    },
    {
        "id": "9ce2c8286e0f8f82",
        "type": "debug",
        "z": "87cdab2ed104ba34",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 910,
        "y": 240,
        "wires": []
    }
]

```

---

<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:** [10 June 2022 15:15 UTC](https://discourse.nodered.org/t/get-value-from-file/63723/9 "2022-06-10T15:15:45Z")

</div>

Again there is an illegal character, at position 0, as `{` is not an illegal character there must be an invisible character created by what ever created the txt file. Again delete the first line and retype it, and try again.

here is an example of an illegal char i have added it to front of text, as you can see, you can not see it in the debug text, but it is there in the template. [Zero-width space - Wikipedia](https://en.m.wikipedia.org/wiki/Zero-width_space)

```auto
[{"id":"67a622fa.69e774","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":230,"y":3040,"wires":[["1806f346.8f2c4d"]]},{"id":"1806f346.8f2c4d","type":"template","z":"bf9e1e33.030598","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"plain","template":"​️{\n \"tikku1nimi\": \"Kanan koipi 4 kpl\",\n \"tikku1väri\": \"Punainen\",\n \"alkulämpö1\": 0,\n \"aloitusaika1\": 0,\n \"lämpösaavutetaan1\": 0,\n \"tikku1pinta\": 0,\n \"tikku1sisä\": 0,\n \"tikku1pintatavoite\": 60,\n \"tikun1loppulämpötila\": 0,\n \"ominaisuuslämpökerroin1\": 3490,\n \"pallo1d\": 0.1,\n \"tiheys1\": 1051,\n \"tikku1sisätavoite\": 60,\n \"tikun1lämmönläpäisykerroin\": 4187.826756018863,\n \"valmistusaika1\": 100,\n \"viive1\": 2\n}","output":"str","x":330,"y":3080,"wires":[["2f24ad7e.810352","cc65f31c.a638f8"]]},{"id":"2f24ad7e.810352","type":"json","z":"bf9e1e33.030598","name":"","property":"payload","action":"","pretty":false,"x":470,"y":3080,"wires":[["cc65f31c.a638f8"]]},{"id":"cc65f31c.a638f8","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":510,"y":3140,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![Kundepuu](https://avatars.discourse-cdn.com/v4/letter/k/bcef8e/32.png) [@Kundepuu](https://discourse.nodered.org/u/Kundepuu)\
**Post date:** [10 June 2022 16:17 UTC](https://discourse.nodered.org/t/get-value-from-file/63723/10 "2022-06-10T16:17:10Z")

</div>

Can you make working txt.file?

---

<div class="post-metadata">

**Author:** ![Kundepuu](https://avatars.discourse-cdn.com/v4/letter/k/bcef8e/32.png) [@Kundepuu](https://discourse.nodered.org/u/Kundepuu)\
**Post date:** [11 June 2022 02:48 UTC](https://discourse.nodered.org/t/get-value-from-file/63723/11 "2022-06-11T02:48:32Z")

</div>

This flow read same file and now it works...

```auto
[
    {
        "id": "b7b23d53af4aa5b7",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "45603ddcb5682875",
        "type": "file in",
        "z": "b7b23d53af4aa5b7",
        "name": "Read Dump_Starterinfo",
        "filename": "",
        "format": "utf8",
        "sendError": true,
        "allProps": false,
        "x": 430,
        "y": 440,
        "wires": [
            [
                "3d00a59e1287f338"
            ]
        ]
    },
    {
        "id": "374ca31c2deea912",
        "type": "inject",
        "z": "b7b23d53af4aa5b7",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": true,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "str",
        "x": 110,
        "y": 320,
        "wires": [
            [
                "6a0ce8bfb177d3f4",
                "3ece076417875c88",
                "e509da6d43905892"
            ]
        ]
    },
    {
        "id": "764e8005c757ddbd",
        "type": "fs-ops-dir",
        "z": "b7b23d53af4aa5b7",
        "name": "",
        "path": "payload",
        "pathType": "msg",
        "filter": "*.dump",
        "filterType": "str",
        "dir": "files",
        "dirType": "msg",
        "x": 480,
        "y": 180,
        "wires": [
            [
                "a5653a60479f902d",
                "424750833d5f2143"
            ]
        ]
    },
    {
        "id": "3ece076417875c88",
        "type": "ui_dropdown",
        "z": "b7b23d53af4aa5b7",
        "name": "",
        "label": "",
        "tooltip": "",
        "place": "Valitse tiedosto",
        "group": "0872231650f59ce7",
        "order": 1,
        "width": 0,
        "height": 0,
        "passthru": true,
        "multiple": false,
        "options": [
            {
                "label": "",
                "value": "",
                "type": "str"
            }
        ],
        "payload": "",
        "topic": "topic",
        "topicType": "msg",
        "className": "",
        "x": 480,
        "y": 260,
        "wires": [
            [
                "f24e07d22e24517b"
            ]
        ]
    },
    {
        "id": "424750833d5f2143",
        "type": "change",
        "z": "b7b23d53af4aa5b7",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "files",
                "pt": "flow",
                "to": "files",
                "tot": "msg"
            },
            {
                "t": "set",
                "p": "polku",
                "pt": "flow",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 760,
        "y": 180,
        "wires": [
            []
        ]
    },
    {
        "id": "a5653a60479f902d",
        "type": "function",
        "z": "b7b23d53af4aa5b7",
        "name": "",
        "func": "msg.options = Object.values(flow.get(\"files\"))\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 480,
        "y": 220,
        "wires": [
            [
                "3ece076417875c88"
            ]
        ]
    },
    {
        "id": "6a0ce8bfb177d3f4",
        "type": "change",
        "z": "b7b23d53af4aa5b7",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "C:\\Kundeager\\",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 460,
        "y": 140,
        "wires": [
            [
                "764e8005c757ddbd"
            ]
        ]
    },
    {
        "id": "f24e07d22e24517b",
        "type": "change",
        "z": "b7b23d53af4aa5b7",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "alustustiedosto1",
                "pt": "flow",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 430,
        "y": 320,
        "wires": [
            [
                "160f6f141286acbc"
            ]
        ]
    },
    {
        "id": "160f6f141286acbc",
        "type": "function",
        "z": "b7b23d53af4aa5b7",
        "name": "",
        "func": "polku=flow.get(\"polku\")+flow.get(\"alustustiedosto1\");\nflow.set(\"alustustiedosto1\",polku);\nmsg.filename=polku\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 480,
        "y": 380,
        "wires": [
            [
                "45603ddcb5682875"
            ]
        ]
    },
    {
        "id": "5e7d11a891b8f135",
        "type": "function",
        "z": "b7b23d53af4aa5b7",
        "name": "",
        "func": "p=msg.payload\nmsg.payload=p.tikku1nimi;\nif(p.tikku1nimi==undefined){\n msg.payload=\" \"\n\n }else{ \n msg.payload=p.tikku1nimi;\n global.set(\"tikku1alustusdata\",p,\"file\") \n }\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 480,
        "y": 540,
        "wires": [
            [
                "0ee49453a738e1bf",
                "e509da6d43905892"
            ]
        ]
    },
    {
        "id": "0ee49453a738e1bf",
        "type": "debug",
        "z": "b7b23d53af4aa5b7",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "x": 770,
        "y": 540,
        "wires": []
    },
    {
        "id": "3d00a59e1287f338",
        "type": "json",
        "z": "b7b23d53af4aa5b7",
        "name": "",
        "property": "payload",
        "action": "",
        "pretty": false,
        "x": 490,
        "y": 500,
        "wires": [
            [
                "5e7d11a891b8f135"
            ]
        ]
    },
    {
        "id": "e509da6d43905892",
        "type": "ui_text",
        "z": "b7b23d53af4aa5b7",
        "group": "0872231650f59ce7",
        "order": 3,
        "width": 0,
        "height": 0,
        "name": "",
        "label": "Tikku1nimi:",
        "format": "{{msg.payload}}",
        "layout": "row-spread",
        "className": "",
        "x": 470,
        "y": 600,
        "wires": []
    },
    {
        "id": "3e8fa2018d842841",
        "type": "ui_spacer",
        "z": "b7b23d53af4aa5b7",
        "name": "spacer",
        "group": "0872231650f59ce7",
        "order": 3,
        "width": 3,
        "height": 1
    },
    {
        "id": "0872231650f59ce7",
        "type": "ui_group",
        "name": "testi",
        "tab": "1de8df1002dbe6df",
        "order": 1,
        "disp": true,
        "width": "6",
        "collapse": false,
        "className": ""
    },
    {
        "id": "1de8df1002dbe6df",
        "type": "ui_tab",
        "name": "Kokeilu",
        "icon": "dashboard",
        "disabled": false,
        "hidden": false
    }
]

```

---

<div class="post-metadata">

**Author:** ![Kundepuu](https://avatars.discourse-cdn.com/v4/letter/k/bcef8e/32.png) [@Kundepuu](https://discourse.nodered.org/u/Kundepuu)\
**Post date:** [11 June 2022 06:11 UTC](https://discourse.nodered.org/t/get-value-from-file/63723/12 "2022-06-11T06:11:43Z")

</div>

Every time when data changed and saved it adds illegal character(s) at he beginning...  
so not solved my problem

---

<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:** [11 June 2022 07:37 UTC](https://discourse.nodered.org/t/get-value-from-file/63723/13 "2022-06-11T07:37:03Z")

</div>

First what is creating the file, do you have control over it, can you fix it there.

If not you could try trimming the payload after the file read node, using a function node with below code.

```auto
msg.payload = msg.payload.trim();
return msg;

```

Or try this this JSONata in a change node.

```auto
[{"id":"374ca31c2deea912","type":"inject","z":"b7b23d53af4aa5b7","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"str","x":110,"y":320,"wires":[["6a0ce8bfb177d3f4","3ece076417875c88","e509da6d43905892"]]},{"id":"6a0ce8bfb177d3f4","type":"change","z":"b7b23d53af4aa5b7","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"C:\\Kundeager\\","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":140,"wires":[["764e8005c757ddbd"]]},{"id":"3ece076417875c88","type":"ui_dropdown","z":"b7b23d53af4aa5b7","name":"","label":"","tooltip":"","place":"Valitse tiedosto","group":"0872231650f59ce7","order":1,"width":0,"height":0,"passthru":true,"multiple":false,"options":[{"label":"","value":"","type":"str"}],"payload":"","topic":"topic","topicType":"msg","className":"","x":480,"y":260,"wires":[["f24e07d22e24517b"]]},{"id":"e509da6d43905892","type":"ui_text","z":"b7b23d53af4aa5b7","group":"0872231650f59ce7","order":3,"width":0,"height":0,"name":"","label":"Tikku1nimi:","format":"{{msg.payload}}","layout":"row-spread","className":"","x":470,"y":600,"wires":[]},{"id":"764e8005c757ddbd","type":"fs-ops-dir","z":"b7b23d53af4aa5b7","name":"","path":"payload","pathType":"msg","filter":"*.dump","filterType":"str","dir":"files","dirType":"msg","x":480,"y":180,"wires":[["a5653a60479f902d","424750833d5f2143"]]},{"id":"a5653a60479f902d","type":"function","z":"b7b23d53af4aa5b7","name":"","func":"msg.options = Object.values(flow.get(\"files\"))\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":220,"wires":[["3ece076417875c88"]]},{"id":"f24e07d22e24517b","type":"change","z":"b7b23d53af4aa5b7","name":"","rules":[{"t":"set","p":"alustustiedosto1","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":320,"wires":[["160f6f141286acbc"]]},{"id":"5e7d11a891b8f135","type":"function","z":"b7b23d53af4aa5b7","name":"","func":"p=msg.payload\nmsg.payload=p.tikku1nimi;\nif(p.tikku1nimi==undefined){\n msg.payload=\" \"\n\n }else{ \n msg.payload=p.tikku1nimi;\n global.set(\"tikku1alustusdata\",p,\"file\") \n }\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":540,"wires":[["0ee49453a738e1bf","e509da6d43905892"]]},{"id":"424750833d5f2143","type":"change","z":"b7b23d53af4aa5b7","name":"","rules":[{"t":"set","p":"files","pt":"flow","to":"files","tot":"msg"},{"t":"set","p":"polku","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":760,"y":180,"wires":[[]]},{"id":"160f6f141286acbc","type":"function","z":"b7b23d53af4aa5b7","name":"","func":"polku=flow.get(\"polku\")+flow.get(\"alustustiedosto1\");\nflow.set(\"alustustiedosto1\",polku);\nmsg.filename=polku\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":380,"wires":[["45603ddcb5682875"]]},{"id":"3d00a59e1287f338","type":"json","z":"b7b23d53af4aa5b7","name":"","property":"payload","action":"","pretty":false,"x":490,"y":500,"wires":[["5e7d11a891b8f135"]]},{"id":"0ee49453a738e1bf","type":"debug","z":"b7b23d53af4aa5b7","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":770,"y":540,"wires":[]},{"id":"45603ddcb5682875","type":"file in","z":"b7b23d53af4aa5b7","name":"Read Dump_Starterinfo","filename":"","format":"utf8","sendError":true,"x":430,"y":440,"wires":[["614e7602.ae286"]]},{"id":"614e7602.ae286","type":"change","z":"b7b23d53af4aa5b7","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"\"{\" & $substringAfter($$.payload,\"{\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":440,"wires":[["3d00a59e1287f338"]]},{"id":"0872231650f59ce7","type":"ui_group","name":"testi","tab":"1de8df1002dbe6df","order":1,"disp":true,"width":"6","collapse":false,"className":""},{"id":"1de8df1002dbe6df","type":"ui_tab","name":"Kokeilu","icon":"dashboard","disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [11 June 2022 08:40 UTC](https://discourse.nodered.org/t/get-value-from-file/63723/14 "2022-06-11T08:40:17Z")

</div>

Try this...

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/c/ecc738b5df1b8a6e068a79f6a73633e46ee8b84b.png)

```auto
[{"id":"374ca31c2deea912","type":"inject","z":"eaa6d97a6ede80ab","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"str","x":450,"y":500,"wires":[["6a0ce8bfb177d3f4","3ece076417875c88","e509da6d43905892"]]},{"id":"6a0ce8bfb177d3f4","type":"change","z":"eaa6d97a6ede80ab","name":"C:/temp","rules":[{"t":"set","p":"polku","pt":"msg","to":"C:/temp","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":320,"wires":[["764e8005c757ddbd"]]},{"id":"3ece076417875c88","type":"ui_dropdown","z":"eaa6d97a6ede80ab","name":"","label":"","tooltip":"","place":"Valitse tiedosto","group":"0872231650f59ce7","order":1,"width":0,"height":0,"passthru":true,"multiple":false,"options":[{"label":"","value":"","type":"str"}],"payload":"","topic":"topic","topicType":"msg","className":"","x":740,"y":440,"wires":[["189b9416b4f47e0f"]]},{"id":"e509da6d43905892","type":"ui_text","z":"eaa6d97a6ede80ab","group":"0872231650f59ce7","order":3,"width":0,"height":0,"name":"","label":"Tikku1nimi:","format":"{{msg.payload}}","layout":"row-spread","className":"","x":750,"y":720,"wires":[]},{"id":"764e8005c757ddbd","type":"fs-ops-dir","z":"eaa6d97a6ede80ab","name":"polku","path":"c:/temp","pathType":"str","filter":"*.dump","filterType":"str","dir":"files","dirType":"msg","x":870,"y":320,"wires":[["a5653a60479f902d"]]},{"id":"a5653a60479f902d","type":"function","z":"eaa6d97a6ede80ab","name":"create options","func":"\n//[{ \"filename\": \"full path\" }]\n\nmsg.options = Object.values(msg.files).map(filename => {\n return {\n [filename]: msg.polku + '/' + filename\n }\n})\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":760,"y":380,"wires":[["3ece076417875c88","f7c089efd06d9866"]]},{"id":"189b9416b4f47e0f","type":"change","z":"eaa6d97a6ede80ab","name":"set msg.filename","rules":[{"t":"set","p":"filename","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":930,"y":440,"wires":[["45603ddcb5682875","2545ac94284dfabe"]]},{"id":"5e7d11a891b8f135","type":"function","z":"eaa6d97a6ede80ab","name":"get value of tikku1nimi","func":"const p = msg.payload\nmsg.payload = p.tikku1nimi;\nif (p.tikku1nimi == undefined) {\n msg.payload = \" \"\n\n} else {\n msg.payload = p.tikku1nimi;\n global.set(\"tikku1alustusdata\", p, \"file\")\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":780,"y":640,"wires":[["e509da6d43905892"]]},{"id":"133f26ce16386305","type":"change","z":"eaa6d97a6ede80ab","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"error.message","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":740,"wires":[["974b80786730ddb6","e509da6d43905892"]]},{"id":"f7c089efd06d9866","type":"debug","z":"eaa6d97a6ede80ab","name":"check options are [{ \"filename\" : \"full file path\" }]","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"options","targetType":"msg","statusVal":"","statusType":"auto","x":1120,"y":380,"wires":[]},{"id":"45603ddcb5682875","type":"file in","z":"eaa6d97a6ede80ab","name":"Read Dump_Starterinfo","filename":"","format":"utf8","sendError":true,"allProps":false,"x":790,"y":520,"wires":[["6392a83225a15117"]]},{"id":"2545ac94284dfabe","type":"debug","z":"eaa6d97a6ede80ab","name":"check filename is full path","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"filename","targetType":"msg","statusVal":"","statusType":"auto","x":1190,"y":440,"wires":[]},{"id":"3d00a59e1287f338","type":"json","z":"eaa6d97a6ede80ab","name":"","property":"payload","action":"","pretty":false,"x":970,"y":580,"wires":[["5e7d11a891b8f135","0ee49453a738e1bf"]]},{"id":"5477a22e380d278b","type":"catch","z":"eaa6d97a6ede80ab","name":"","scope":["45603ddcb5682875","5e7d11a891b8f135","3d00a59e1287f338","6392a83225a15117"],"uncaught":false,"x":430,"y":660,"wires":[["133f26ce16386305","0e4a511fed42da85"]]},{"id":"974b80786730ddb6","type":"ui_toast","z":"eaa6d97a6ede80ab","position":"top right","displayTime":"3","highlight":"red","sendall":false,"outputs":0,"ok":"OK","cancel":"","raw":false,"className":"","topic":"","name":"","x":770,"y":760,"wires":[]},{"id":"6392a83225a15117","type":"function","z":"eaa6d97a6ede80ab","name":"clean file data to ascii","func":"let fd = msg.payload.trim();\nfd = fd.normalize('NFD').replace(/[\\u0300-\\u036f]/g, \"\")\nfd = fd.replace(/[\\u{0080}-\\u{FFFF}]/gu, \"\");\nfd = fd.replace(/[^\\x20-\\x7E]+/g, '');\nmsg.payload = fd\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":780,"y":580,"wires":[["3d00a59e1287f338"]]},{"id":"0ee49453a738e1bf","type":"debug","z":"eaa6d97a6ede80ab","name":"should be JS Object","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1200,"y":580,"wires":[]},{"id":"0e4a511fed42da85","type":"debug","z":"eaa6d97a6ede80ab","name":"errors","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":470,"y":600,"wires":[]},{"id":"0872231650f59ce7","type":"ui_group","name":"testi","tab":"1de8df1002dbe6df","order":1,"disp":true,"width":"6","collapse":false,"className":""},{"id":"1de8df1002dbe6df","type":"ui_tab","name":"Kokeilu","icon":"dashboard","disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

**Author:** ![Kundepuu](https://avatars.discourse-cdn.com/v4/letter/k/bcef8e/32.png) [@Kundepuu](https://discourse.nodered.org/u/Kundepuu)\
**Post date:** [12 June 2022 01:30 UTC](https://discourse.nodered.org/t/get-value-from-file/63723/15 "2022-06-12T01:30:08Z")

</div>

I have used Notepad long time and never get this error issue in other projects (not used node red before).  
So then changing something in the file and save it adds those illegal letters at the beginning.  
Both your solution works now well  
Thanks!

 ![illegal chars](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/d/7d0ec4aad79acd661000ef5f3f3accf4bfc57be7.png)  
 ![Steve-Mcl](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/a/2a4d929b5c99a7e070efbb04160087143d81bb3c.jpeg)  
 ![E1cid](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/8/c8076d8ba392dcaf6ed23d6bd53513a09ea615cd.jpeg)

---

<div class="post-metadata">

**Author:** ![Kundepuu](https://avatars.discourse-cdn.com/v4/letter/k/bcef8e/32.png) [@Kundepuu](https://discourse.nodered.org/u/Kundepuu)\
**Post date:** [12 June 2022 13:37 UTC](https://discourse.nodered.org/t/get-value-from-file/63723/16 "2022-06-12T13:37:59Z")

</div>

Steve-Mcl  
your code changes scandinavian chars ä to a and ö to o...

original data in file

```auto
{"nimi":"Kanan koipi kpl","väri":"Punainen","aloitusaika":0,"valmistusaika":100,"alkulämpö":5,"sisälämpösaavutetaan":212,"pinta":60,"sisätavoite":60,"sisä":40,"pintatavoite":60,"loppulämpötila":43,"ominaisuuslämpokerroin":3490,"lämmönläpäisykerroin":4187.826756018863,"muoto":"Pallo","tiheys":1051,"pallod":0.1,"kuutios":0.1,
"sylinterih":0.1,"sylinterid":0.1,"tiiliskivil":0.1,"tiiliskiviw":0.1,"tiiliskivih":0.1,"raaka_aine":"Kana","tuote":"Koipi","viive":2}

```

your edit node code "clean file data to ascii"

```auto
let fd = msg.payload.trim();
fd = fd.normalize('NFD').replace(/[\u0300-\u036f]/g, "")
fd = fd.replace(/[\u{0080}-\u{FFFF}]/gu, "");
fd = fd.replace(/[^\x20-\x7E]+/g, '');
msg.payload = fd
return msg;

```

and it return

```auto
{"nimi":"Kanan koipi kpl","vari":"Punainen","aloitusaika":0,"valmistusaika":100,"alkulampo":5,"sisalamposaavutetaan":212,"pinta":60,"sisatavoite":60,"sisa":40,"pintatavoite":60,"loppulampotila":43,"ominaisuuslampokerroin":3490,"lammonlapaisykerroin":4187.826756018863,"muoto":"Pallo","tiheys":1051,"pallod":0.1,"kuutios":0.1,"sylinterih":0.1,"sylinterid":0.1,"tiiliskivil":0.1,"tiiliskiviw":0.1,"tiiliskivih":0.1,"raaka_aine":"Kana","tuote":"Koipi","viive":2}

```

can you fix it?

---

<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:** [26 June 2022 13:38 UTC](https://discourse.nodered.org/t/get-value-from-file/63723/17 "2022-06-26T13:38:34Z")

</div>

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