# Show ALL attributes data

**URL:** <https://discourse.nodered.org/t/show-all-attributes-data/5879>\
**Category:** General\
**Created:** [17 December 2018 11:03 UTC](https://discourse.nodered.org/t/show-all-attributes-data/5879 "2018-12-17T11:03:26Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![WppNL](https://avatars.discourse-cdn.com/v4/letter/w/ecae2f/32.png) [@WppNL](https://discourse.nodered.org/u/WppNL)\
**Post date:** [17 December 2018 11:03 UTC](https://discourse.nodered.org/t/show-all-attributes-data/5879/1 "2018-12-17T11:03:26Z")

</div>

I am tracking packages from a carrier which works perfectly.  
At the moment i receive a Telegram message with the info: "you have X packages".

But i want to see where the packages comes from. I can see this info in the attributes data but i don't know how to extract it because the company is named different everytime.  
 ![WqYFXmm](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/2637dcddc8c8d240d009ab51decab7f89272a26e.png)

In this example I want to send the text "999 Games" and "Memory-Garden vof" to my phone.

Is this possible without knowing upfront what's in the attributes data?

---

<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:** [17 December 2018 13:39 UTC](https://discourse.nodered.org/t/show-all-attributes-data/5879/2 "2018-12-17T13:39:19Z")

</div>

> [@WppNL](#):
>
> Is this possible without knowing upfront what's in the attributes data?

If you don't know what the attributes are how would you determine which attributes to send?  
[Edit] just noticed the post title says All attributes, but the example you gave you say you only want some of them.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [17 December 2018 17:27 UTC](https://discourse.nodered.org/t/show-all-attributes-data/5879/3 "2018-12-17T17:27:27Z")

</div>

Is the order of the data the same every time? i.e. is the company name the key of the second part of the attributes object?

---

<div class="post-metadata">

**Author:** ![JayDickson](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jaydickson/32/90592_2.png) [@JayDickson](https://discourse.nodered.org/u/JayDickson)\
**Post date:** [17 December 2018 18:18 UTC](https://discourse.nodered.org/t/show-all-attributes-data/5879/4 "2018-12-17T18:18:39Z")

</div>

Do you have other examples? It looks like "friendly\_name:" "Unit\_of\_measurement" "attribution" and "icon" would be always present or at the very least not company names. You might be able to use a split node to send all parts of the attributes object as individual messages and use the switch node to filter out any unwanted parts.

---

<div class="post-metadata">

**Author:** ![WppNL](https://avatars.discourse-cdn.com/v4/letter/w/ecae2f/32.png) [@WppNL](https://discourse.nodered.org/u/WppNL)\
**Post date:** [17 December 2018 19:31 UTC](https://discourse.nodered.org/t/show-all-attributes-data/5879/5 "2018-12-17T19:31:18Z")

</div>

I have found a way myself. It's probably not the most efficient way but I am a random guy having fun with node-red, not a Software developer.

@zenofmud I think it depends on how many packages i will receive so no.  
@JayDickson This is how i fixed it. I filtered all the attributes that are always present (friendly\_name, unit\_of\_measurement, icon, attribution). And the usefull data will be filtered with "otherwise" on the switch node.

```auto
 [{"id":"fab7ae08.18ab9","type":"server-state-changed","z":"3d3f5fac.25e4b","name":"PostNL","server":"cac0837e.bc9b7","entityidfilter":"sensor.postnl","entityidfiltertype":"substring","haltifstate":"","outputinitially":true,"x":129,"y":244,"wires":[["a2999169.d632a"]]},{"id":"ec925256.48edc","type":"comment","z":"3d3f5fac.25e4b","name":"PostNL","info":"","x":129,"y":194.43750190734863,"wires":[]},{"id":"a2999169.d632a","type":"switch","z":"3d3f5fac.25e4b","name":"&gt;=1 pakketjes","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"1","vt":"num"}],"checkall":"false","repair":false,"outputs":1,"x":304.2421989440918,"y":243.4375114440918,"wires":[["1a24f4a9.43fc7b"]]},{"id":"1a24f4a9.43fc7b","type":"function","z":"3d3f5fac.25e4b","name":"Atttributes splitsen","func":"var attributes = msg.data.new_state.attributes;\n\nreturn[{payload:attributes}]","outputs":1,"noerr":0,"x":536.8333911895752,"y":243.66671562194824,"wires":[["4aa1f7e4.eefaf8"]]},{"id":"48048c31.bb49c4","type":"switch","z":"3d3f5fac.25e4b","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"Information provided by PostNL","vt":"str"},{"t":"eq","v":"packages","vt":"str"},{"t":"eq","v":"postnl","vt":"str"},{"t":"eq","v":"mdi:package-variant-closed","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":5,"x":864.1668510437012,"y":243.6666717529297,"wires":[[],[],[],[],["9388a722.c832b8"]]},{"id":"9388a722.c832b8","type":"split","z":"3d3f5fac.25e4b","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":1054.0001907348633,"y":240.00004291534424,"wires":[["af1394e9.909098"]]},{"id":"af1394e9.909098","type":"function","z":"3d3f5fac.25e4b","name":"Bericht","func":"msg.payload = \n{ text: `Op ${msg.payload} komt er een pakketje van ${msg.parts.parts.key} `, \nparse_mode: \"Markdown\" };\n\nreturn msg;","outputs":1,"noerr":0,"x":1210.0000343322754,"y":240.00004768371582,"wires":[["d5ebfbd3.0bc0f8"]]},{"id":"d5ebfbd3.0bc0f8","type":"telegrambot-payload","z":"3d3f5fac.25e4b","name":"Versturen","bot":"76d092d0.28022c","chatId":"667099650","sendMethod":"sendMessage","payload":"","x":1381.0000381469727,"y":240.00004768371582,"wires":[[]]},{"id":"4aa1f7e4.eefaf8","type":"split","z":"3d3f5fac.25e4b","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":728.1667671203613,"y":244.00009536743164,"wires":[["48048c31.bb49c4"]]},{"id":"cac0837e.bc9b7","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":false,"rejectUnauthorizedCerts":true},{"id":"76d092d0.28022c","type":"telegrambot-config","z":"","botname":"Kevintelegrambot","usernames":"","chatIds":"667099650","pollInterval":"300"}]
```

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [30 December 2018 04:12 UTC](https://discourse.nodered.org/t/show-all-attributes-data/5879/6 "2018-12-30T04:12:28Z")

</div>

> [@WppNL](#):
>
> In this example I want to send the text "999 Games" and "Memory-Garden vof" to my phone.
> 
> Is this possible without knowing upfront what's in the attributes data?

This is possible by utilizing a JSONata expression that navigates to the part of the structure with the attributes object, and then returns only the field names that are _not_ recognized (i.e. `icon`, `friendly_name`, etc).

The first step is to hover the cursor over that `attributes` object, and when the little buttons appear on the right side, select the first one to copy the "path" to that object. From the picture you posted, it looks to be `msg.data.new_state.attributes` -- so assuming that's correct, you can use this expression to first strip off the "recognized" fields, and return only the keys (field names) that are left:

```auto
$keys(data.new_state.attributes ~> | $ | {}, ["attribution", "unit_of_measurement", "friendly_name", "icon"] | )[]

```

Another approach that may be less cryptic would be to get all the keys, and then filter out the ones that you recognize as not being store names:

```auto
$keys(data.new_state.attributes)[$ != "attribution" and $ != "unit_of_measurement" and $ != "friendly_name" and $ != "icon"][]

```

Still quite an ugly expression, especially if there are lots of field names that you need to exclude. From this little bit of data, it _appears_ like we can return only the field names that contain valid date strings -- in which case, we can use a regular expression to look for matches, like so:

```auto
[$sift(data.new_state.attributes, /\d{4}-\d{2}-\d{2}/) ~> $keys()]

```

Try using one of these expressions in a `change` node -- just be sure to select the `J:` JSONata expression option, not the `{}` JSON text option... it even has a built-in expression tester that you can use against your actual data copied from the debug side panel.

---

<div class="post-metadata">

**Author:** ![WppNL](https://avatars.discourse-cdn.com/v4/letter/w/ecae2f/32.png) [@WppNL](https://discourse.nodered.org/u/WppNL)\
**Post date:** [21 February 2019 22:58 UTC](https://discourse.nodered.org/t/show-all-attributes-data/5879/7 "2019-02-21T22:58:47Z")

</div>

Unfortunately none of the 3 options work for me. I don't have any coding skills so I really don't know how to change them correctly.
