Receiving Object with too many levels and save it to a new object structure

Hello Node-Red-Community,

I have some difficulties to make a solution for the following topics:

  • Make a new JS object with names and values for each line (combined with the header object)

I get objects from a machine.
The machine outputs the content 1 three times: (always the same)

{"ASYS":{"ALIVE_RES":[{"$":{"s_source":"077591","s_type":"AES03 Speed","l_msgCount":"0"}}]}}

After this the machine outputs 3 contentes for each line:
Line 1
{"ASYS":{"WARNING":[{"$":{"l_warningNb":"21","l_come":"0","s_warningText":"","l_lane":"1","l_value1":"0","l_value2":"0","l_magazineWidth":"0"}}]}}

Line 2
{"ASYS":{"WARNING":[{"$":{"l_warningNb":"21","l_come":"0","s_warningText":"","l_lane":"2","l_value1":"0","l_value2":"0","l_magazineWidth":"0"}}]}}

Line 3
{"ASYS":{"WARNING":[{"$":{"l_warningNb":"21","l_come":"0","s_warningText":"","l_lane":"3","l_value1":"0","l_value2":"0","l_magazineWidth":"0"}}]}}

I wanna have the the content of each Machine-line additional the content of the first object:

s_source: value (if no value, just nothing)
s_type: value (if no value, just nothing)
l_msgCount: value (if no value, just nothing)
l_warningNb: value (if no value, just nothing)
l_come: value (if no value, just nothing)
s_warningText: value (if no value, just nothing)
l_lane: value (if no value, just nothing)
l_value1: value (if no value, just nothing)
l_value2: value (if no value, just nothing)
1_magazineWidth: value (if no value, just nothing)

For me I tried several days to find a solution to make it in a function node, but my program skills are really bad, even though it looks so easy :confused:

On top, there is sometimes a message in the line "s_warningText" which looks like:
{"ASYS":{"WARNING":[{"$":{"l_warningNb":"2086","l_come":"1","s_warningText":"00:00 Restlaufzeit, 2 Restkapazit�t, Vorwarngrenze erreicht.","l_lane":"3","l_value1":"0","l_value2":"2","l_magazineWidth":"0"}}]}}

In the word "Restkapazit�t it should be "ae" instead the "�", so my idea is to search the for "Restkapa" delete 5 characters and insert "zitaet"

I hope someone could help me :smiley:

If some more information are missing, please let me know.

Greetings
Michael

May be not the most elegant way - but may it works as you expect it:

[
    {
        "id": "4a7f4b3ef130d9d4",
        "type": "change",
        "z": "5e8ed48429d10959",
        "name": "ASYS.ALIVE_RES",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "payload.ASYS.ALIVE_RES",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 710,
        "y": 380,
        "wires": [
            [
                "8faf474fc40fbc38"
            ]
        ]
    },
    {
        "id": "b653681c874c61f0",
        "type": "change",
        "z": "5e8ed48429d10959",
        "name": "ASYS.WARNING",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "payload.ASYS.WARNING",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 710,
        "y": 440,
        "wires": [
            [
                "e35a3f3888711ae7"
            ]
        ]
    },
    {
        "id": "8faf474fc40fbc38",
        "type": "switch",
        "z": "5e8ed48429d10959",
        "name": "defined?",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "nnull"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 900,
        "y": 380,
        "wires": [
            [
                "e59e5080919d72ed"
            ]
        ]
    },
    {
        "id": "e35a3f3888711ae7",
        "type": "switch",
        "z": "5e8ed48429d10959",
        "name": "defined?",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "nnull"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 900,
        "y": 440,
        "wires": [
            [
                "25d8b8cb18f4a18a"
            ]
        ]
    },
    {
        "id": "e59e5080919d72ed",
        "type": "change",
        "z": "5e8ed48429d10959",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "{\t    \"s_source\": **.s_source,\t    \"s_type\": **.s_type,\t    \"l_msgCount\": **.l_msgCount,\t    \"l_warningNb\": \"\",\t    \"l_come\": \"\",\t    \"s_warningText\": \"\",\t    \"l_lane\": \"\",\t    \"l_value1\": \"\",\t    \"l_value2\": \"\",\t    \"1_magazineWidth\": \"\"\t}",
                "tot": "jsonata"
            },
            {
                "t": "set",
                "p": "obj",
                "pt": "flow",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1090,
        "y": 380,
        "wires": [
            []
        ]
    },
    {
        "id": "cf33dbe1ac011522",
        "type": "debug",
        "z": "5e8ed48429d10959",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 1470,
        "y": 440,
        "wires": []
    },
    {
        "id": "25d8b8cb18f4a18a",
        "type": "change",
        "z": "5e8ed48429d10959",
        "name": "",
        "rules": [
            {
                "t": "move",
                "p": "payload[0].$.l_warningNb",
                "pt": "msg",
                "to": "obj.l_warningNb",
                "tot": "flow"
            },
            {
                "t": "move",
                "p": "payload[0].$.l_come",
                "pt": "msg",
                "to": "obj.l_come",
                "tot": "flow"
            },
            {
                "t": "move",
                "p": "payload[0].$.s_warningText",
                "pt": "msg",
                "to": "obj.s_warningText",
                "tot": "flow"
            },
            {
                "t": "move",
                "p": "payload[0].$.l_lane",
                "pt": "msg",
                "to": "obj.l_lane",
                "tot": "flow"
            },
            {
                "t": "move",
                "p": "payload[0].$.l_value1",
                "pt": "msg",
                "to": "obj.l_value1",
                "tot": "flow"
            },
            {
                "t": "move",
                "p": "payload[0].$.l_value2",
                "pt": "msg",
                "to": "obj.l_value2",
                "tot": "flow"
            },
            {
                "t": "move",
                "p": "payload[0].$.l_magazineWidth",
                "pt": "msg",
                "to": "obj.l_magazineWidth",
                "tot": "flow"
            },
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "obj",
                "tot": "flow"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1090,
        "y": 440,
        "wires": [
            [
                "1dcbeb8121f71513"
            ]
        ]
    },
    {
        "id": "1dcbeb8121f71513",
        "type": "change",
        "z": "5e8ed48429d10959",
        "name": "translations",
        "rules": [
            {
                "t": "change",
                "p": "payload.s_warningText",
                "pt": "msg",
                "from": "Restkapazit�t",
                "fromt": "str",
                "to": "Restkapazität",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1290,
        "y": 440,
        "wires": [
            [
                "cf33dbe1ac011522"
            ]
        ]
    },
    {
        "id": "99a2ed2b47b553a8",
        "type": "group",
        "z": "5e8ed48429d10959",
        "name": "Simulate Input",
        "style": {
            "label": true
        },
        "nodes": [
            "a9bf94cee5d63b0e",
            "132541d204836007",
            "a09a58e2db1a6042",
            "5dd3a0cb7bea560f",
            "94a4715ecd310b81"
        ],
        "x": 74,
        "y": 279,
        "w": 472,
        "h": 222
    },
    {
        "id": "a9bf94cee5d63b0e",
        "type": "inject",
        "z": "5e8ed48429d10959",
        "g": "99a2ed2b47b553a8",
        "name": "Alive_Res",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{\"ASYS\":{\"ALIVE_RES\":[{\"$\":{\"s_source\":\"077591\",\"s_type\":\"AES03 Speed\",\"l_msgCount\":\"0\"}}]}}",
        "payloadType": "json",
        "x": 200,
        "y": 320,
        "wires": [
            [
                "a09a58e2db1a6042"
            ]
        ]
    },
    {
        "id": "132541d204836007",
        "type": "inject",
        "z": "5e8ed48429d10959",
        "g": "99a2ed2b47b553a8",
        "name": "Warning Line1",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{\"ASYS\":{\"WARNING\":[{\"$\":{\"l_warningNb\":\"21\",\"l_come\":\"0\",\"s_warningText\":\"\",\"l_lane\":\"1\",\"l_value1\":\"0\",\"l_value2\":\"0\",\"l_magazineWidth\":\"0\"}}]}}",
        "payloadType": "json",
        "x": 190,
        "y": 380,
        "wires": [
            [
                "a09a58e2db1a6042"
            ]
        ]
    },
    {
        "id": "a09a58e2db1a6042",
        "type": "change",
        "z": "5e8ed48429d10959",
        "g": "99a2ed2b47b553a8",
        "name": "Machine input",
        "rules": [],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 440,
        "y": 400,
        "wires": [
            [
                "4a7f4b3ef130d9d4",
                "b653681c874c61f0"
            ]
        ]
    },
    {
        "id": "5dd3a0cb7bea560f",
        "type": "inject",
        "z": "5e8ed48429d10959",
        "g": "99a2ed2b47b553a8",
        "name": "Warning Line2",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{\"ASYS\":{\"WARNING\":[{\"$\":{\"l_warningNb\":\"21\",\"l_come\":\"0\",\"s_warningText\":\"\",\"l_lane\":\"2\",\"l_value1\":\"0\",\"l_value2\":\"0\",\"l_magazineWidth\":\"0\"}}]}}",
        "payloadType": "json",
        "x": 190,
        "y": 420,
        "wires": [
            [
                "a09a58e2db1a6042"
            ]
        ]
    },
    {
        "id": "94a4715ecd310b81",
        "type": "inject",
        "z": "5e8ed48429d10959",
        "g": "99a2ed2b47b553a8",
        "name": "Warning Line3",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{\"ASYS\":{\"WARNING\":[{\"$\":{\"l_warningNb\":\"2086\",\"l_come\":\"1\",\"s_warningText\":\"00:00 Restlaufzeit, 2 Restkapazit�t, Vorwarngrenze erreicht.\",\"l_lane\":\"3\",\"l_value1\":\"0\",\"l_value2\":\"2\",\"l_magazineWidth\":\"0\"}}]}}",
        "payloadType": "json",
        "x": 190,
        "y": 460,
        "wires": [
            [
                "a09a58e2db1a6042"
            ]
        ]
    }
]
1 Like

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