How to parse message parts to variables

No problem.

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;

So if msg.payload.device = S5 I want to get 4.

Is that any help to what I was wanting to do?

Understood, thanks

I had trouble understanding the structure I was shown.
(Looking beyond the mistake I missed.)

I think I am starting to understand it, but I honestly am not familiar with it and so I can't just look at it and understand it.

I never did C++ or JS programming when I was younger. Mostly BASIC. So neatly structured code is not something I am used to.

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.

1 Like

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