[SOLVED] JSONPATH and 2 or more values at same time

Hi!
What the easiest way to extract 2 or 3 values from JSONPATH message?
I need to create Item from every value?

{"port":0,"m":0,"value":"ON","click":1,"cnt":204}

Is it possible to get something like that from “m” & “click”: “0, 2” in one Item?

Maybe something like this in a rule and use postUpdate to give the value, but I have no idea what you plan to do with the info. If your using the data for more than viewing then an item is needed. I think.:thinking:

Example in a rule.

var String jsonstring= "{\"m\":0,\"click\":\"1\",\"cnt\":204}"
Some_item.postUpdate(jsonstring)

First question is: What are you trying to achieve?
How do you acquire the json string?
What are you trying to do with the data in the json?

This is MQTT message from home automation controller, it has 56 ports
It produce 4 events: single click, double click, holded 1,5sec, release after holding.
I want to find simplest way to manage this message and get wall switch status.

Here is the rules that works, but i don’t want 56 copies of this rule :exploding_head:

//message {"port":0,"m":0,"value":"ON","click":1,"cnt":204}

rule "test"
when
    Item but_0 changed
then
    var m     = transform("JSONPATH", "$.m",     but_0 .state.toString)
    var click = transform("JSONPATH", "$.click", but_0 .state.toString)

    if ( m == "2" ) {
        //hold
        numBut_0.postUpdate(3)
    } else if ( click == "1" ) {
         numBut_0.postUpdate(1)
    } else if ( click == "2" ) {
        numBut_0.postUpdate(2)
    } else if ( m == "1" ) {
        //release        
        numBut_0.postUpdate(4)
    }

end

I solved it by adding JS transformation rule to the Item:

(function(message){
    //{"port":0,"m":0,"value":"ON","click":1,"cnt":214}
    var array = message.split(",");
    var m = 0;
    if (array[1] == "\"m\":1") m = 4;
    if (array[1] == "\"m\":2") m = 3;
    if (array[3] == "\"click\":1") m = 1;
    if (array[3] == "\"click\":2") m = 2;
    return m;
})
(input)