# Using Object Key as Dynamic Label Text Output

**URL:** <https://discourse.nodered.org/t/using-object-key-as-dynamic-label-text-output/59020>\
**Category:** Dashboard\
**Tags:** node-red-dashboard, function-node\
**Created:** [26 February 2022 12:25 UTC](https://discourse.nodered.org/t/using-object-key-as-dynamic-label-text-output/59020 "2022-02-26T12:25:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![CheeKC](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cheekc/32/52442_2.png) [@CheeKC](https://discourse.nodered.org/u/CheeKC)\
**Post date:** [26 February 2022 12:25 UTC](https://discourse.nodered.org/t/using-object-key-as-dynamic-label-text-output/59020/1 "2022-02-26T12:25:56Z")

</div>

Hi,  
I am trying to access the Msg Object Key as a dynamic label for text label in a NodeRED Dashboard display but has difficulty in finding way to extract the "Key" value.

I have a MQTT data object stream that receives digital input status from a PLC and I need to display the respective "Key" text (e.g. Di1, Di2..) as label on the NodeRED dashboard. As these Key text are dynamic and changes, I cannot use static typed text for the {{label}}.  
 ![Screenshot 2022-02-26 at 8.14.23 PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/2/9236a01c7baaeadd605b836f88e4d2fc354aa752.png)

I tried to split the object "Key and Value pair" stream and is able to get the individual "Value" results.

![Screenshot 2022-02-26 at 8.18.38 PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/5/d59f300dd5b364e7e24b6bb83e02138346a53717.png)

 ![Screenshot 2022-02-26 at 8.16.56 PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/9/2968c3f131aa924f9cc8c67be2b5af4005128236.png)

However, I am stuck on how to extract each of the "Key" value as text to be submitting to the Dashboard Label.

Attached is my flow and dashboard for reference.

```auto
[{"id":"47616595f9d59619","type":"tab","label":"Flow 4","disabled":false,"info":"","env":[]},{"id":"99d62f342708aa0d","type":"mqtt in","z":"47616595f9d59619","name":"","topic":"v1/2158061268/DiM2/values","qos":"2","datatype":"json","broker":"db51a71cd38877ec","nl":false,"rap":true,"rh":0,"inputs":0,"x":180,"y":120,"wires":[["b36f9801a0c5787c","58cbfbf67defd0dc","27ad9e552208fd89","1d39b4bbe220122a"]]},{"id":"e2cff9f0e0ef72d1","type":"debug","z":"47616595f9d59619","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.params","targetType":"msg","statusVal":"","statusType":"auto","x":600,"y":120,"wires":[]},{"id":"b36f9801a0c5787c","type":"function","z":"47616595f9d59619","name":"","func":"var Dix = msg.payload.params.Di1;\n\nif (Dix == '1') {\n (msg.payload='ON')}\n else {\n (msg.payload='OFF')}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":400,"y":220,"wires":[["48abc233580983c2","6b85fa7cbb345b13"]]},{"id":"48abc233580983c2","type":"debug","z":"47616595f9d59619","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":590,"y":220,"wires":[]},{"id":"6b85fa7cbb345b13","type":"ui_text","z":"47616595f9d59619","group":"9a6348a506085d0e","order":1,"width":"3","height":"1","name":"Di1 Status","label":"Di1 (hardcode)","format":"{{msg.payload}}","layout":"row-center","className":"","x":610,"y":280,"wires":[]},{"id":"58cbfbf67defd0dc","type":"function","z":"47616595f9d59619","name":"","func":"var Dix = msg.payload.params.Di2;\n\nif (Dix == '1') {\n (msg.payload='ON')}\n else {\n (msg.payload='OFF')}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":400,"y":360,"wires":[["6ee7759595ecadb3","a1c0c70ca4cacd6c"]]},{"id":"6ee7759595ecadb3","type":"debug","z":"47616595f9d59619","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":590,"y":360,"wires":[]},{"id":"a1c0c70ca4cacd6c","type":"ui_text","z":"47616595f9d59619","group":"9a6348a506085d0e","order":1,"width":"3","height":"1","name":"Di2 Status","label":"{{label}}","format":"{{msg.payload}}","layout":"row-center","className":"","x":610,"y":420,"wires":[]},{"id":"27ad9e552208fd89","type":"change","z":"47616595f9d59619","name":"","rules":[{"t":"move","p":"payload.params","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":260,"y":540,"wires":[["5a99ee725e91ef8d"]]},{"id":"5a99ee725e91ef8d","type":"split","z":"47616595f9d59619","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":470,"y":540,"wires":[["072b120e3313bf7b"]]},{"id":"1d39b4bbe220122a","type":"function","z":"47616595f9d59619","name":"","func":"msg.item = msg.payload[msg.index];\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":400,"y":120,"wires":[["e2cff9f0e0ef72d1"]]},{"id":"072b120e3313bf7b","type":"debug","z":"47616595f9d59619","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":630,"y":540,"wires":[]},{"id":"db51a71cd38877ec","type":"mqtt-broker","name":"DAXView Mini SG","broker":"1160ee3168524d998cb5c33af5355c22.s1.eu.hivemq.cloud","port":"8883","tls":"","clientid":"E92m","autoConnect":true,"usetls":true,"protocolVersion":"5","keepalive":"70","cleansession":false,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""},{"id":"9a6348a506085d0e","type":"ui_group","name":"Di Status","tab":"8f41e4d6436371f2","order":1,"disp":true,"width":"6","collapse":false,"className":""},{"id":"8f41e4d6436371f2","type":"ui_tab","name":"Di Status","icon":"dashboard","disabled":false,"hidden":false}]

```

Any suggestion is greatly appreciated.

Best Regards,  
KC

---

<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 February 2022 12:43 UTC](https://discourse.nodered.org/t/using-object-key-as-dynamic-label-text-output/59020/2 "2022-02-26T12:43:23Z")

</div>

Try a split node and copy key to topic then you can use `topic` as label and `payload` as value

After split node, you can use a switch node to redirect the individual messages by topic

---

<div class="post-metadata">

**Author:** ![CheeKC](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cheekc/32/52442_2.png) [@CheeKC](https://discourse.nodered.org/u/CheeKC)\
**Post date:** [26 February 2022 14:32 UTC](https://discourse.nodered.org/t/using-object-key-as-dynamic-label-text-output/59020/3 "2022-02-26T14:32:41Z")

</div>

Hi Steve,  
Thanks for the solution.  
It solved my problem.

Best Regards,  
KC

---

<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:** [12 March 2022 14:33 UTC](https://discourse.nodered.org/t/using-object-key-as-dynamic-label-text-output/59020/4 "2022-03-12T14:33:34Z")

</div>

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