JSONPATH Transformation Service vs. JSONPATH

The workaround is to use jq and exec transformation instead of jsonpath transformation.

I would suggest to open a new thread and post the rules which fail. So you might get help. I think there is no general answer to your question.

could you please advise?

I can run a curl command with the jq formatted filter and get the desired result, how do I allocate this to an item?

Use the Exec binding

Exec binding

Another option is to use a rule with executeCommandLine (look under Workaround in the first post), then update the item.

1 Like

Can you show me your syntax/structure of the exec command?

I got it working using a thing, item and script ( to execute curl with the jq filter) for each object of the array. It works but it’s very clunky I’d prefer to not have to use the scripts to pull the data.ill also need all 3 for every piece of data I’m trying to assign to an item.

I’m not a developer if that wasn’t clear!

1 Like

Thanks Josar, I am in over my head. I need to learn to code if I am going to continue on with the feature I am working on.

I’m querying the API of my kegbot to check keg levels

edit: I’ve done a bit more reading. I am trying to use the exec binding to send a curl command. It works fine in the shell however when executing with exec binding it does not like characters in the command string. Do I need special characters for spaces etc?

here is the thing

Thing exec:command:kegbot_poll6 [command="/usr/bin/curl -sS | \jq '.objects[5].current_keg.volume_ml_remain'", interval=60, timeout=5]

And the item

String tap6_vol_remaining {channel="exec:command:kegbot_poll6:output"}

not sure if what you try to do with jq will work. Try to go one step after another, first fetch the date with curl, if this works try to transform it. If it does not work in the command line you can transform it with a transformation services at the Thing, Item or maybe a rule.

it returns the value from the shell it has to be the syntax with the exec binding I think.

I can get it working with a separate script that the thing executes and the the item is assigned the output.

Its fine I will just do it this way, now I need to convert the output to a number somehow.

rhanks Josar I used


sorry getting OT now


tap1_vol_remaining_num.postUpdate(Double::parseDouble(tap1_vol_remaining.state.toString) / 1000)

did the trick

Time to trim to 2 decimals…

edit: success!

I just used the habpanel widget to trim to two decimals.


Any progress here to let us get the list result of an undefinite transform path in the rules ? (without having to deal with all the messing stuff with exec binding and external tools)

17:28:47.467 [WARN ] [nternal.JSonPathTransformationService] - JsonPath expressions with more than one result are not allowed, please adapt your selector. Result: [“kitchen”,“room”]

I really can’t understand the logic : if what I want is “[“kitchen”,“room”]” and that’s correctly computed by the function, why someone would explicitely want to forbid me to access it ?

Writing an undefinite transformation path is precisely for getting a undefinite result… if I want exactly one result, I write a definite transformation path :slight_smile:

Or at least, could you provide an optional parameter to the transform function, with a default value making the function return NULL instead of the result, and the result otherwise ?



@romain you have to find another workaround as the maintainer have the opinion that transformation services have to return a valid data value, no data collection. And using Items as datastorage is not the right way to go.
If i remember right also a single data pair "name" : value can be returned, but i am not quite sure.

Have a look here, you may ask there how to solve your problem.

I’ve migrated to JSR223-Jython, and one of the many benefits is that I can use the built in json module for parsing JSON in my rules. But TBH, there are a couple places I still use executeCommandLine and jq.

In case there was confusion, the EXEC binding isn’t needed for the workaround I provided. And jq is a nice utility that can do much more than parse JSON.

Hm. No. I know you wanted to write something else. Something like:

… have the opinion that transformation services have to return a single element from the transformed json.

If you need more elements, you need to do more transformations.

I am confused here… recently upgraded to 2.3.0 and this transformation broke for me.
Why can’t the transformation just return a single string with the json encoded text like it did before?
This used to work.

String  _WeatherHourly_json  "JSON [%s]"       {http="<[http://api.wunderground.com/api/28f2a6af09069287/hourly/q/45.4347982,-75.5739861.json:900000:JSONPATH($.hourly_forecast)]"}

This would give me a string that I could further parse in my rules very easily.
If I have to make more specific transformations, i will need to add 65 more items!

Have a look in the linked github issue discussion a few posts above.

This is ridiculous, everything i see online shows that this:


Should return:


Give me a single string object!
Its right there in the logs:

2018-10-13 13:41:00.019 [WARN ] [ternal.JSonPathTransformationService] - JsonPath expressions with more than one result are not allowed, please adapt your selector. Result: ["8","8","8","8","7","6","5","4","4","4","4","3","3"]

You have made this implementation non-standard so that it returns Outside instead of [ "Outside" ]. If you wanted something non-standard, you should have created another transformation.

Actually, that is a List<String> object, which was the problem that the PR was trying to resolve, since Items will only accept Strings.

You have found the essence of the difference between JSONPATH and the JSONPATH transformation service! You may want to express your opinion in the PR linked to in the first post… everyone here is in the same boat as you and dealing with the aftermath.

In the meantime, I suggest you look into using executeCommandLine, curl and pr, or the JS transformation service, for parsing json in scripts.