# How to extract object names with special characters?

**URL:** <https://discourse.nodered.org/t/how-to-extract-object-names-with-special-characters/30897>\
**Category:** General\
**Created:** [29 July 2020 22:56 UTC](https://discourse.nodered.org/t/how-to-extract-object-names-with-special-characters/30897 "2020-07-29T22:56:45Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gawan](https://avatars.discourse-cdn.com/v4/letter/g/e9c0ed/32.png) [@Gawan](https://discourse.nodered.org/u/Gawan)\
**Post date:** [29 July 2020 22:56 UTC](https://discourse.nodered.org/t/how-to-extract-object-names-with-special-characters/30897/1 "2020-07-29T22:56:46Z")

</div>

Hi,  
my Tasmota Temperature Sensor with two sensor devices is delivering object names with the following name:

msg.payload.DS18B20-1.Temperature  
msg.payload.DS18B20-2.Temperature

Unfortunately Node-Red can neither read DS18B20-1 nor DS18B20-2 as a valid object name.

It says: Expected an identifier and saw "DS18B20-1"

Unfortunately this IS my identifier and I have no idea what I can do to get these values from these objects.

Any ideas out there ?

BR  
Gawan

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [29 July 2020 23:03 UTC](https://discourse.nodered.org/t/how-to-extract-object-names-with-special-characters/30897/2 "2020-07-29T23:03:02Z")

</div>

When a property contains special characters you can use the alternative syntax:

```auto
msg.payload["DS18B20-1"].Temperature

```

---

<div class="post-metadata">

**Author:** ![Gawan](https://avatars.discourse-cdn.com/v4/letter/g/e9c0ed/32.png) [@Gawan](https://discourse.nodered.org/u/Gawan)\
**Post date:** [29 July 2020 23:14 UTC](https://discourse.nodered.org/t/how-to-extract-object-names-with-special-characters/30897/3 "2020-07-29T23:14:19Z")

</div>

wow ... it really works 😃 😃 😃

How did you know that ???

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [29 July 2020 23:16 UTC](https://discourse.nodered.org/t/how-to-extract-object-names-with-special-characters/30897/4 "2020-07-29T23:16:36Z")

</div>

It's JavaScript - [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property\_Accessors](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors)

---

<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:** [30 July 2020 06:26 UTC](https://discourse.nodered.org/t/how-to-extract-object-names-with-special-characters/30897/5 "2020-07-30T06:26:54Z")

</div>

In addition you would make your life easier if you used underscore instead of - in the names.

---

<div class="post-metadata">

**Author:** ![Gawan](https://avatars.discourse-cdn.com/v4/letter/g/e9c0ed/32.png) [@Gawan](https://discourse.nodered.org/u/Gawan)\
**Post date:** [31 July 2020 06:13 UTC](https://discourse.nodered.org/t/how-to-extract-object-names-with-special-characters/30897/6 "2020-07-31T06:13:38Z")

</div>

unfortunately the naming is done by the Tasmota firmware automatically and it is creating a serially numbered ID

---

<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:** [31 July 2020 07:32 UTC](https://discourse.nodered.org/t/how-to-extract-object-names-with-special-characters/30897/7 "2020-07-31T07:32:49Z")

</div>

> [@Gawan](#):
>
> it is creating a serially numbered ID

Yes you are right, there have been discussions about making it variable bit it has not happened yet. In this situation then personally I would pick up the value and immediately republish it to MQTT with a more meaningful name (home/bedroom/temperature or whatever matches your naming convention) and use that.

---

<div class="post-metadata">

**Author:** ![Gawan](https://avatars.discourse-cdn.com/v4/letter/g/e9c0ed/32.png) [@Gawan](https://discourse.nodered.org/u/Gawan)\
**Post date:** [31 July 2020 07:45 UTC](https://discourse.nodered.org/t/how-to-extract-object-names-with-special-characters/30897/8 "2020-07-31T07:45:42Z")

</div>

yes, that makes sense ... but nevertheless I have to read them once from MQTT with these IDs 🙂

instead of republishing them, I am using global variables in Node-Red a LOT to store the values temporarily

---

<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:** [31 July 2020 08:58 UTC](https://discourse.nodered.org/t/how-to-extract-object-names-with-special-characters/30897/9 "2020-07-31T08:58:35Z")

</div>

> [@Gawan](#):
>
> nevertheless I have to read them once from MQTT with these IDs

You would just need a change node between the mqtt nodes, so the minus wouldn't be a problem.

> [@Gawan](#):
>
> I am using global variables in Node-Red a LOT to store the values temporarily

A bad idea in my opinion. Just pick them up direct from mqtt. Then your flows automatically get triggered when the values change.

---

<div class="post-metadata">

**Author:** ![Gawan](https://avatars.discourse-cdn.com/v4/letter/g/e9c0ed/32.png) [@Gawan](https://discourse.nodered.org/u/Gawan)\
**Post date:** [31 July 2020 09:04 UTC](https://discourse.nodered.org/t/how-to-extract-object-names-with-special-characters/30897/10 "2020-07-31T09:04:13Z")

</div>

Thats not how my setup works 🙂

I get MQTT messages whenever a parameter changes (or every 10 secs via Tasmota if they do not change) and store them in global variables in Node-Red (approx 200 different in total right now.)  
All subsequent process steps (like writing the value to SQL database or showing them in a chart) is timewise independent and simply reads the latest value from Global Vars.

E.g. it does not make sense for me to store some figures every 10 sec into the SQL DB - there is another process that triggers every 15 mins  
Linecharts get new data every 2 mins

If I need a live-trigger from a MQTT-message I connect the step in parallel to the process step that writes the Global Vars

---

<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:** [31 July 2020 09:16 UTC](https://discourse.nodered.org/t/how-to-extract-object-names-with-special-characters/30897/11 "2020-07-31T09:16:12Z")

</div>

None of those are major reasons for using globals, there are ways of achieving the same same functionality without, but it is a personal choice.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [31 July 2020 09:21 UTC](https://discourse.nodered.org/t/how-to-extract-object-names-with-special-characters/30897/12 "2020-07-31T09:21:07Z")

</div>

or use an RBE node to filter out duplicates and only write immediately they actually do change.

---

<div class="post-metadata">

**Author:** ![Gawan](https://avatars.discourse-cdn.com/v4/letter/g/e9c0ed/32.png) [@Gawan](https://discourse.nodered.org/u/Gawan)\
**Post date:** [31 July 2020 10:19 UTC](https://discourse.nodered.org/t/how-to-extract-object-names-with-special-characters/30897/13 "2020-07-31T10:19:08Z")

</div>

> [@Colin](#):
>
> None of those are major reasons for using globals, there are ways of achieving the same same functionality without, but it is a personal choice.

Are there ?

I am using the Global Vars as "single point of information" for my whole Node-Red Installation.

e.g. I do an online-monitoring by verifying the latest UpdateTimeStamp of a Global-Var-Object - independent of the MQTT-Input side

or I compare up to 4 parameters to decide a "next process step" - independent when they were updated the last time - like if I turn on the light in the garage when its bright or dark outside  
the bright or dark parameter is delivered via MQTT, but changes only twice a day, so I have to store it somewhere

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [31 July 2020 10:21 UTC](https://discourse.nodered.org/t/how-to-extract-object-names-with-special-characters/30897/14 "2020-07-31T10:21:19Z")

</div>

For your scenario, your use of context values is perfectly sensible and what they are intended for.

MQTT is great if you need to trigger something when a value changes.

But if you have flows that run independently of the MQTT nodes that need to refer to the latest values, then context is the perfect solution.

---

<div class="post-metadata">

**Author:** ![Gawan](https://avatars.discourse-cdn.com/v4/letter/g/e9c0ed/32.png) [@Gawan](https://discourse.nodered.org/u/Gawan)\
**Post date:** [31 July 2020 10:23 UTC](https://discourse.nodered.org/t/how-to-extract-object-names-with-special-characters/30897/15 "2020-07-31T10:23:32Z")

</div>

hm ... yes, but thats what I do 🙂  
I use context values ... and there we have NODE, FLOW and GLOBAL

what I do is setting the global values

---

<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:** [31 July 2020 10:42 UTC](https://discourse.nodered.org/t/how-to-extract-object-names-with-special-characters/30897/16 "2020-07-31T10:42:26Z")

</div>

> [@Gawan](#):
>
> what I do is setting the global values

> [@Gawan](#):
>
> approx 200 different in total right now

Just curious. Do you have these as separate global variables or as properties of 1 or 2 objects that are stored in global?

I do something similar where values come from many different sources - but are related & I need to know values independentantly. I pack them up into an object that I store in flow or global context - makes things easier to manage and visualise.

---

<div class="post-metadata">

**Author:** ![Gawan](https://avatars.discourse-cdn.com/v4/letter/g/e9c0ed/32.png) [@Gawan](https://discourse.nodered.org/u/Gawan)\
**Post date:** [31 July 2020 10:49 UTC](https://discourse.nodered.org/t/how-to-extract-object-names-with-special-characters/30897/17 "2020-07-31T10:49:34Z")

</div>

> [@Steve-Mcl](#):
>
> Just curious. Do you have these as separate global variables or as properties of 1 or 2 objects that are stored in global?

One device (e.g. sensor for water temperature) is one object consisting of a TimeStamp (in readable format), a serialized TimeStamp (for Usage in Node-Red), sometimes a devicename (for ESP8266 sensors and actors) and 0-x measured values  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/9/698f41b427db75751b1a3667b6c33da0042b2372.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/6/863693289182eb0c0063206201293420ff8c750c.png)

I really like it because it is slim and easy to use 🙂

and in most cases the whole object is updated by one specific MQTT package

---

<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:** [14 August 2020 10:49 UTC](https://discourse.nodered.org/t/how-to-extract-object-names-with-special-characters/30897/18 "2020-08-14T10:49:38Z")

</div>

Closed on 14 August 2020 10:49 UTC

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