Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON input can only match on exact msg.payload string #48

Closed
deelerke opened this issue Jan 7, 2020 · 2 comments
Closed

JSON input can only match on exact msg.payload string #48

deelerke opened this issue Jan 7, 2020 · 2 comments

Comments

@deelerke
Copy link

deelerke commented Jan 7, 2020

hi, there is an option to select JSON input for the msg.payload, but it seems to only test the whole string. So the LED would only colorize when the complete string is matched.
Is it possible to select which JSON element & value to test?
For example: an input would look like: { "Light1":0,"Light2":1,"Light3":0,"Light4":1 }
And then have the led node to test:
if "Light1" == "1" then color = "green"
if "Light1" == "0" then color = "grey"
That way you can connect many ui-leds to a single input and select on what element to light up.

see: https://discourse.nodered.org/t/simple-json-input-string-to-leds-on-dash/20003

THANKS!

@yoiang
Copy link
Member

yoiang commented Jul 17, 2020

Hello @deelerke !
Sorry for the very late reply!
As outlined in the thread you currently will have to split up the values that come through your initial payload and direct the appropriate one to the LED you'd like to process that value. It is a lot of repetitive work but a lot of that can be solved by using subflows.

I am struggling to think of a robust but also intuitive way to allow using properties within an object type payload. Are there any other nodes you feel do this well? Perhaps an option to compare the direct value or as an object and if one selects object they must also specify a property. This could get complicated, people requesting path support for sub-sub-sub properties, etc.

Edit below:

It's been a little since I've messed around with the node, just played a little more and I have some thoughts, let me know what you think:

Right now the node is using Node-RED's compareObjects method which tests exact match. We could add an option that says instead test that the properties of the matching payload defined in the Colors for value of msg.payload are all present and equal in our actual payload.

So for example:

Match

Test

{
   "value" : false,
   "value2" : true
}

Payload

{
   "value" : false,
   "value1.5" : false,
   "value2" : true
}

No match

Test

{
   "value" : false,
   "value2" : true
}

Payload // Missing "value2"

{
   "value" : false,
   "value1.5" : false
}

Payload // value2's value does not match

{
   "value" : false,
   "value1.5" : false,
   "value2" : false
}

@yoiang yoiang added enhancement New feature or request suggestion and removed enhancement New feature or request labels Jul 17, 2020
@yoiang
Copy link
Member

yoiang commented Jan 21, 2021

Looking back on this I think there isn't a very extendable but also non-power user style interface that I can imagine, and it feels like it would be more flexible to keep this functionality in a separate place, such as a function or switch node.

However if anyone still has a strong argument feel free to drop it here!

@yoiang yoiang closed this as completed Jan 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants