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

**URL:** <https://discourse.nodered.org/t/receiving-object-with-too-many-levels-and-save-it-to-a-new-object-structure/63687>\
**Category:** General\
**Tags:** function-node\
**Created:** [9 June 2022 15:04 UTC](https://discourse.nodered.org/t/receiving-object-with-too-many-levels-and-save-it-to-a-new-object-structure/63687 "2022-06-09T15:04:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vanilla-sky](https://avatars.discourse-cdn.com/v4/letter/v/7bcc69/32.png) [@vanilla-sky](https://discourse.nodered.org/u/vanilla-sky)\
**Post date:** [9 June 2022 15:04 UTC](https://discourse.nodered.org/t/receiving-object-with-too-many-levels-and-save-it-to-a-new-object-structure/63687/1 "2022-06-09T15:04:56Z")

</div>

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)_

```auto
{"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 😕

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 😃

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

Greetings  
Michael

---

<div class="post-metadata">

**Author:** ![mickym2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mickym2/32/36128_2.png) [@mickym2](https://discourse.nodered.org/u/mickym2)\
**Post date:** [9 June 2022 15:15 UTC](https://discourse.nodered.org/t/receiving-object-with-too-many-levels-and-save-it-to-a-new-object-structure/63687/2 "2022-06-09T15:15:42Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/9/0952e8de873223bde0c51d52ba6b71ccf386b56b.png)

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

```

---

<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:** [23 June 2022 15:15 UTC](https://discourse.nodered.org/t/receiving-object-with-too-many-levels-and-save-it-to-a-new-object-structure/63687/3 "2022-06-23T15:15:57Z")

</div>

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