Form two separate Objects from received one object

Hello, everyone. I have a question to split one Object that is received as a msg.payload on one of the nodes like the one below

{Time: "2021-07-23T20:09:33.985Z", Voltage: 12.0, Current: 1.2, S: 1, Su: 0}

I want to know if there is a node or a function that can be added to that node to split them in a specific order like this

{Time: "2021-07-23T20:09:33.985Z", Voltage: 12.0, S: 1}
{Time: "2021-07-23T20:09:33.985Z", Current: 1.2, Su: 0}

Thank you guys for your help so far.

A function node (set to 2 outputs) is probably easiest...

const m1 = {
    payload: {
        Time: msg.payload.Time,
        Voltage: msg.payload.Voltage,
        S: msg.payload.S,
    }
}
const m2 = {
    payload: {
        Time: msg.payload.Time,
        Current: msg.payload.Current,
        Su: msg.payload.Su,
    }
}

return [m1, m2];

However you can do this with 2 change nodes and JSONata

[{"id":"905288fad5edf836","type":"change","z":"e78eac1c.8b9cf","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\t    \"Time\": payload.Time,\t    \"Voltage\": payload.Voltage,\t    \"S\": payload.S\t}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1940,"y":320,"wires":[["97cd287a6bda91ae"]]},{"id":"3a7eb1100423f34a","type":"inject","z":"e78eac1c.8b9cf","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"Time\":\"2021-07-23T20:09:33.985Z\",\"Voltage\":12,\"Current\":1.2,\"S\":1,\"Su\":0}","payloadType":"json","x":1770,"y":340,"wires":[["905288fad5edf836","ac6d7af029189b8d"]]},{"id":"97cd287a6bda91ae","type":"debug","z":"e78eac1c.8b9cf","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":2150,"y":320,"wires":[]},{"id":"ac6d7af029189b8d","type":"change","z":"e78eac1c.8b9cf","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\t    \"Time\": payload.Time,\t    \"Current\": payload.Current,\t    \"Su\": payload.Su\t}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1940,"y":360,"wires":[["7d33a4c58ac81906"]]},{"id":"7d33a4c58ac81906","type":"debug","z":"e78eac1c.8b9cf","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":2150,"y":360,"wires":[]}]

Or 2 change nodes and several delete entries...

[{"id":"905288fad5edf836","type":"change","z":"e78eac1c.8b9cf","name":"delete Current and Su","rules":[{"t":"delete","p":"payload.Current","pt":"msg"},{"t":"delete","p":"payload.Su","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1960,"y":320,"wires":[["97cd287a6bda91ae"]]},{"id":"3a7eb1100423f34a","type":"inject","z":"e78eac1c.8b9cf","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"Time\":\"2021-07-23T20:09:33.985Z\",\"Voltage\":12,\"Current\":1.2,\"S\":1,\"Su\":0}","payloadType":"json","x":1770,"y":340,"wires":[["905288fad5edf836","e377caf92f7b5c53"]]},{"id":"97cd287a6bda91ae","type":"debug","z":"e78eac1c.8b9cf","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":2150,"y":320,"wires":[]},{"id":"7d33a4c58ac81906","type":"debug","z":"e78eac1c.8b9cf","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":2150,"y":360,"wires":[]},{"id":"e377caf92f7b5c53","type":"change","z":"e78eac1c.8b9cf","name":"delete Voltage and S","rules":[{"t":"delete","p":"payload.Voltage","pt":"msg"},{"t":"delete","p":"payload.S","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1960,"y":360,"wires":[["7d33a4c58ac81906"]]}]

Amazing, thank you so much for that easy solution

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