Exec JSONPATH

Hi,
Is it possible to apply jsonpath to the item?
i have a thing that gets a json result.

Thing exec:command:testitem [command="python /etc/openhab2/scripts/test.py", interval=900, timeout=10]
{ "store": {
    "book": [ 
      { "category": "reference",
        "author": "Nigel Rees",
        "title": "Sayings of the Century",
        "price": 8.95
      },
      { "category": "fiction",
        "author": "Evelyn Waugh",
        "title": "Sword of Honour",
        "price": 12.99
      },
      { "category": "fiction",
        "author": "Herman Melville",
        "title": "Moby Dick",
        "isbn": "0-553-21311-3",
        "price": 8.99
      },
      { "category": "fiction",
        "author": "J. R. R. Tolkien",
        "title": "The Lord of the Rings",
        "isbn": "0-395-19395-8",
        "price": 22.99
      }
    ],
    "bicycle": {
      "color": "red",
      "price": 19.95
    }
  }
}

This does not work

String test "test" {channel="exec:command:testitem:output:JSONPATH($.store.bicycle.price)"}

You need to add the transform to the Thing as documented in the Readme.

You don’t add the transform to the Item when using 2.x bindings.

OK i did read that but i couldent belive it. I thougt all about 2.x was the thing represent lots of items, guess not in this binding then. I cant run the exec 20 times in a row just to fetch 20 values wich are in the same response every time…
I guess im doing a rule insted then

Not in any binding. That is an incorrect understanding of what Things do. A Thing represents a single device (or equivalent). Each control point or information provided is represented by a Channel. A Channel gets linked to an Item.

In the case of the exec binding, the “device” is a script and the Channels provided are for starting the script, input, output, etc. But the binding, being a generic binding, only provides one output channel.

Perhaps someday someone will add something like the caching ability like what is in the 1.x HTTP binding for exec 2.x, but since that capability never existed in the 1.x binding and adding something like that to any 2.x binding will likely be challenging, I suspect no one thought to add it yet.

1 Like

You also have the option to use the 1.x Exec binding in OH2.

The 1.x Exec will have the same problem. OP wants to avoid executing the script multiple times when all the information he wants to parse out into multiple Items is returned on every execution.

Gotcha… I read too quickly! I keep doing that…

Thank you for taking the time to explain. I understand the concept now.