Create an object from msg.payload

can someone please tell me how to create an object from any number of messages from my flow?

msg1 = {};
msg1.payload = {"Spreizung KT": msg.payload};
msg2 = {};
msg2.payload = {"THub": Number(msg.payload)};
msg3 = {};
msg3.payload = {"Leistung nach ZH": msg.payload};
return msg1,msg2,msg3;

this function doesn´t work, it makes 3x objects.

the output of the function should be like the buffer parser output:


let msg1 = {"payload":{}};
msg1.payload.Spreizung KT= msg.payload;
msg1.payload["Leistung nach ZH"]=msg.payload;
return msg1;

Then dont make 3 objects - update the payload of 1 object instead.

msg.payloadOrig = msg.payload;
msg.payload = {
  "Spreizung_KT": msg.payload,
  "THub": Number(msg.payload),
  "Leistung_nach_ZH": msg.payload
return msg;

for debugging and other reasons I wont go into right now, it is usually best to re-use the original msg object instead of creating new objects.

This wont work - you cant have spaces in a property name unless you use [] square bracket notation.

Cheers missed the spaces, edited code.

I´m a fool, just finished taking the join node :crazy_face: :woozy_face:
javascript is tough

Most things are tough initially. Don't worry about it.

i always like to learn new things. :nerd_face:
Javascript can do so much and I probably don't even know 1% of it.

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