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

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


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}"

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"
    Item but_0 changed
    var m     = transform("JSONPATH", "$.m",     but_0 .state.toString)
    var click = transform("JSONPATH", "$.click", but_0 .state.toString)

    if ( m == "2" ) {
    } else if ( click == "1" ) {
    } else if ( click == "2" ) {
    } else if ( m == "1" ) {


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

    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;