# Accessing msg properties that have a non standard variable identifier

**URL:** <https://discourse.nodered.org/t/accessing-msg-properties-that-have-a-non-standard-variable-identifier/27316>\
**Category:** General\
**Created:** [26 May 2020 13:15 UTC](https://discourse.nodered.org/t/accessing-msg-properties-that-have-a-non-standard-variable-identifier/27316 "2020-05-26T13:15:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tfmeier](https://avatars.discourse-cdn.com/v4/letter/t/a9a28c/32.png) [@tfmeier](https://discourse.nodered.org/u/tfmeier)\
**Post date:** [26 May 2020 13:15 UTC](https://discourse.nodered.org/t/accessing-msg-properties-that-have-a-non-standard-variable-identifier/27316/1 "2020-05-26T13:15:03Z")

</div>

I'm running into a problem with a function block to create fields for an InfluxDB connector. I use the JSON string to object conversion node in Node-RED and it correctly creates the object {"CF1":1,"CF2.5":1,"CF10":1,"PM1":1,"PM2.5":1,"PM10":1,"PB0.3":348,"PB0.5":89,"PB1":8,"PB2.5":0,"PB5":0,"PB10":0} which I then use as input to the function block below. The error is "a leading decimal point can be confused with a dot". I can see how this could be a problem but have no idea to pick up these values correctly. Any idea?

```auto
msg.payload = {
    cf1: msg.PMS5003.cf1,
    cf2.5: msg.PMS5003.cf2.5, <error
    cf10: msg.PMS5003.cf10,
    pm1: msg.PMS5003.pm1,
    pm2.5: msg.PMS5003.pm2.5, <error
    pm10: msg.PMS5003.pm10,
    pb0.3: msg.PMS5003.pb0.3, <error
    pb0.5: msg.PMS5003.pb0.5,
    pb1: msg.PMS5003.pb1,
    pb2.5: msg.PMS5003.pb2.5, <error
    pb5: msg.PMS5003.pb5,
    pb10: msg.PMS5003.pb10
}
return msg;

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [26 May 2020 13:29 UTC](https://discourse.nodered.org/t/accessing-msg-properties-that-have-a-non-standard-variable-identifier/27316/2 "2020-05-26T13:29:46Z")

</div>

Hi firstly, in order to make code more readable and importable it is important to post it between two sets of three backticks - ``` - see this post for more details - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

As for your issue, use `msg.PMS5003["pm2.5"]` when the variable contains non valid variable name charcaters.

PS, this is called [bracket notation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors)

---

<div class="post-metadata">

**Author:** ![tfmeier](https://avatars.discourse-cdn.com/v4/letter/t/a9a28c/32.png) [@tfmeier](https://discourse.nodered.org/u/tfmeier)\
**Post date:** [26 May 2020 13:43 UTC](https://discourse.nodered.org/t/accessing-msg-properties-that-have-a-non-standard-variable-identifier/27316/3 "2020-05-26T13:43:22Z")

</div>

Thanks Steve on both fronts. That did the trick. You probably can tell that I'm at the deep end of the learning curve 🙂

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [26 May 2020 14:13 UTC](https://discourse.nodered.org/t/accessing-msg-properties-that-have-a-non-standard-variable-identifier/27316/4 "2020-05-26T14:13:26Z")

</div>

If you are generating that data then it might be better to use underscore rather than dot, or just leave it out completely if that still gives you a unique name. Otherwise you will be forever cursing yourself in the future for making life harder. 🙂

---

<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 June 2020 14:13 UTC](https://discourse.nodered.org/t/accessing-msg-properties-that-have-a-non-standard-variable-identifier/27316/5 "2020-06-09T14:13:30Z")

</div>

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