How can I use values in an array inside of an object inside of an array as a condition?

This payload is coming from an RSS feed being read by the Home Assistant RSS Feed Reader integration. I have a node watching the event bus, filtering out all messages that don't have the event_type feedreader.

The idea is this...create a push notification to specific Home Assistant users based upon whether or not a Blog Post was categorized or tagged with a specific value, which will be found under msg.payload.event.tags as an object (index) inside of an array (tags) inside of an object (event) inside of an object (payload).

I want to search msg.payload.event.tags for specific strings under term: then direct the flow based upon that/those findings.

If, for example, the category is "Household" then the flow would proceed one direction, and if the category is "Family" then it would go down a different flow.

The reason I need a search is because the index position of each category/tag may or may not change for each event (i.e. blog post) depending upon the category/tags on the blog post, so simply assigning a value to an index won't work.

  "event_type": "feedreader",
  "event": {
    "title": "Test Post 5",
    "link": "",
    "author": "Author Guy",
    "published": "Mon, 12 Sep 2022 03:03:24 +0000",
    "tags": [
        "term": "Home Assistant",
        "scheme": null,
        "label": null
        "term": "Information Technology",
        "scheme": null,
        "label": null

Is this something that would require the Function node or can it be done without any coding? Either way, I can adapt. Thanks!

Normally use a switch node. In the selector on top specify
msg.payload.event.tags.term and then you put your keywords underneath and assign different exits

Tags is an array, so it would have to be msg.payload.event.tags[0].term which becomes a problem if the blog post has a wide array of tags and categories assigned to it.

One post may be categorized under "apples" and another post would be under "oranges" but both of those would be in the index [0] unless the post was categorized both Apples AND oranges, in which case the position of each value is different than the switch test, which requires the index value.

What I need is to search the array for the value no matter what position it is in.

Set some property to the term you want, and use a switch node with a jsonata expression:


If you want to filter/route multiple:

1 Like

I'm confused by this and don't know how it will solve the problem.

If I have a blog post that is categorized as "Home Assistant" and has no other tags, then the tags array will have a single item in the array indexed at [0]. But, if that blog post has two or more categories, then the array grows and the index positions may or may not be the same.

If I tag post 1 with "Apples", it lands in position [0].
If I tag post 1 with "Apples" and "Oranges", one gets position [0] and the other gets [1].
If I tag post 1 with "Apples" and "Bananas", we have yet another [0] and [1] only this time one of them is different than the 2nd example.

The goal here is to send a notification only to the people who are supposed to get it based upon the category or categories tagged in the post. If the category doesn't warrant a notification, nothing will happen, but if the category does warrant a notification, it will be sent to the correct people.

So, if I wanted to notify the "Apple" people and the "Orange" people with post 1, I would categorize the blog post under both Apples and Oranges, and then NodeRED would send the message down the flow according to the values in the term field in the tags array.

"Hey NodeRED, see this array? I've created a flow specifically for two of the possible categories that come through. If the array contains Apples, send the message to the Apple people. If it contains Oranges, send it to the Oranges people. In fact, send a copy of the message down every flow for which I've defined a category to listen to."

I'm having a hard time explaining this.

Ah sorry there can be multiple tags. you can do an or. I dont have access to my nr atm, but the documentation of jsonata could help out perhaps.

According to you example object tags is under msg.payload.tags, not msg.payload.event.tags.

This should work

[{"id":"e71226f6.8de52","type":"inject","z":"aaa27ee4852b402b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"event_type\":\"feedreader\",\"event\":{\"title\":\"Test Post 5\"},\"link\":\"\",\"author\":\"Author Guy\",\"published\":\"Mon, 12 Sep 2022 03:03:24 +0000\",\"tags\":[{\"term\":\"Home Assistant\",\"scheme\":null,\"label\":null},{\"term\":\"Information Technology\",\"scheme\":null,\"label\":null}]}","payloadType":"json","x":360,"y":460,"wires":[["753c2a9b.5c3d2c"]]},{"id":"753c2a9b.5c3d2c","type":"switch","z":"aaa27ee4852b402b","name":"","property":"payload.tags[*].term","propertyType":"jsonata","rules":[{"t":"cont","v":"Home Assistant","vt":"str"},{"t":"cont","v":"Information Technology","vt":"str"},{"t":"cont","v":"anohter","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":490,"y":460,"wires":[["e0bb140c.d00e7"],["fd4f8aa4.7323c"],["7081c992.f39a1"]]},{"id":"e0bb140c.d00e7","type":"debug","z":"aaa27ee4852b402b","name":"Homa assistant","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":690,"y":440,"wires":[]},{"id":"fd4f8aa4.7323c","type":"debug","z":"aaa27ee4852b402b","name":"Information Technology","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":710,"y":480,"wires":[]},{"id":"7081c992.f39a1","type":"debug","z":"aaa27ee4852b402b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":680,"y":540,"wires":[]}]
1 Like

Ahh...this makes sense. Thanks.

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