But I think you missed what I wanted to do.
I send a big message with a heap of extra stuff on it.
The real message comes in and all these extra things get put on it.
Then depending on the value of one of the msg.payload.(something) points to part of the extra stuff stuck on the message.
I wanted to parse / get that value.
Eg: msg.payload.device = S21 msg.S21 = 3
The device part can change and there are other entries for other devices.
Eg (again) `msg.S5 = 4;
Yes, it can be rather a shock to have to get to grips with JavaScript object structures. But simply said, it is a hierarchy. Mostly the hierarchy can be accessed via the dot notation msg.payload.something. However, there are a couple of exceptions.
If the property name is complex such as starting with a number, containing a character that JavaScript would misinterpret (e.g. - or +) or containing a space.
If you need to access a property via a variable.
In those cases, you access the property using bracket notation as you would if accessing the element of an array.
Count yourself lucky! I've only done a bit and never professionally. I hate it.
It was learning Python that really taught me about object-based design (classes, etc) which was useful when I moved over to using JavaScript for both front- and back-end development.
Of course, my professional development days are long gone so I am a constant learner and re-learner.