Does switch node support a "full text" search of message?

Hi,
I'm new to red node and stumbled upon a problem where my switch node using "contains" does not work as expected.
I have a device that sends a message like this:
{"action":"up_press","action_duration":null,"battery":77,"linkquality":174,"update":{"state":"idle"},"update_available":null}

I use a switch node with property: msg.payload and contains "up_", but that doesnt work. If I use property.payload.action, it works. I understand that action is nested within payload, but why does contains not do a recursive or full text search? I'd expect it to get the whole JSON object, and the object contains "up_".
So, two questions:
a) What is the conceptual reason why it is done this way, so I can learn more about node reds way of thinking.
b) how can I achieve a recursive or full body search with a switch node (in case I don't know exactly where the text will be)

The contains rule expects to operate on a string. It doesn't do a full search of arbitrary nested properties.

Because it was added as a way to check if a string property contains some text. It just wasn't considered as an operation to search into an object's properties. You are the first person I can recall asking otherwise.

Off the top of my head, the only solution I can thnk of is to first use the JSON node to convert the object to a single JSON string that the Switch node can then search it as a single property.

I must admit that's a surprise, I'd expect it to search whatever it is passed.

Is the same true for "Matches regex"?

Yes. Strings can be tested against a regex - objects cannot.

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