Get value from file

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 (453 Bytes)

flows (11).json (3.6 KB)

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

[{"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.

In my post there are flow and text files
your flow gives error
10.6.2022 klo 21.09.30node: c86866be853dfca3msg : string[40]
"Unexpected token in JSON at position 0"

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

[{"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.

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


flows (12).json (1.9 KB)

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.

{
    "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
}
[
    {
        "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": []
    }
]

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

[{"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":[]}]

Can you make working txt.file?

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

[
    {
        "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
    }
]

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

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.

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

Or try this this JSONata in a change node.

[{"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}]

Try this...

[{"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}]

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!



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

original data in file

{"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"

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

{"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?

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