# How to parse message parts to variables

**URL:** https://discourse.nodered.org/t/how-to-parse-message-parts-to-variables/74192
**Category:** General
**Created:** [25 January 2023 21:09 UTC](https://discourse.nodered.org/t/how-to-parse-message-parts-to-variables/74192 "2023-01-25T21:09:16Z")
**Posts on this page:** 5
**Page:** 2

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [26 January 2023 09:11 UTC](https://discourse.nodered.org/t/how-to-parse-message-parts-to-variables/74192/21 "2023-01-26T09:11:12Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [26 January 2023 09:39 UTC](https://discourse.nodered.org/t/how-to-parse-message-parts-to-variables/74192/22 "2023-01-26T09:39:56Z")

</div>

Understood, thanks

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [26 January 2023 09:42 UTC](https://discourse.nodered.org/t/how-to-parse-message-parts-to-variables/74192/23 "2023-01-26T09:42:40Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [26 January 2023 11:31 UTC](https://discourse.nodered.org/t/how-to-parse-message-parts-to-variables/74192/24 "2023-01-26T11:31:08Z")

</div>

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.

> [@Trying\_to\_learn](#):
>
> I never did C++

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.

---

<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: [9 February 2023 11:31 UTC](https://discourse.nodered.org/t/how-to-parse-message-parts-to-variables/74192/25 "2023-02-09T11:31:40Z")

</div>

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

[Previous page](https://discourse.nodered.org/t/how-to-parse-message-parts-to-variables/74192.md?page=1)
