JSONPATH Transformation Service vs. JSONPATH

OK… your results would be much different with a current snapshot.

Is this the way to set the version to snapshot

    sudo rm /etc/apt/sources.list.d/openhab2.list
    echo 'deb https://openhab.jfrog.io/openhab/openhab-linuxpkg unstable main' | sudo tee /etc/apt/sources.list.d/openhab2.list
    sudo apt update
    sudo apt upgrade

I have a manual install, so I’m no help there!

Updated and now i at least get an error in the log for mal formatted json when it contains linebreaks.

Besides of that. My previous post is still valid for the lables.
In the rule the behaviour change as it returns no arrays and strips double quotes. So evaluated objects and no valid json.

You may also notice JSONPATH transforms with indefinite paths will now work for items/labels/bindings, because it will return a String.

please post a valid indefinate query for my TestString2.

$..phoneNumbers[?(@.type=="iPhone")].number

This would solve my issue with the change, i don’t care about the exact format, as long as all information is contained.

Also the change path is pretty clear, if someone needs the brackets, he can simply add them.

In a rule

[ERROR] [core.transform.actions.Transformation] - Error executing the transformation 'JSONPATH': An error occurred while transforming JSON expression.

So also in the label not working.

I am on 2.3.0-SNAPSHOT Build #1219

EDIT: Wrong quotes. This works in the rule but not in a label.

$..[?(@.type=='iPhone')].number

Did you escape the double quotes? Maybe just use single quotes.

We’re a bit off topic, but here are some examples that work for me on #1218

Test_String_2.sendCommand("{ \"firstName\" : \"John\", \"lastName\" : \"doe\",\"age\" : 26, \"address\" : { \"streetAddress\" : \"naist street\",\"city\" : \"Nara\", \"postalCode\" : \"630-0192\" }, \"phoneNumbers\" : [ { \"type\" : \"iPhone\", \"number\" : \"0123-4567-8888\"}, { \"type\" : \"home\", \"number\" : \"0123-4567-8910\" } ] }")
Text item=Test_String_2 label="Virtual String 2 [JSONPATH($..[?(@.type=='iPhone')].number):%s]"// returned 0123-4567-8888 as String
Text item=Test_String_2 label="Virtual String 2 [JSONPATH($..number):%s]"// returned NULL because List.size>1

Test_String_2.sendCommand("{\"Time\": \"2018-01-06T12:56:59\",\"DS18B20-1\": {\"Id\": \"000005FB25D0\",\"Temperature\": 3.2},\"DS18B20-2\": {\"Id\": \"031680634EFF\",\"Temperature\": -18.9},\"TempUnit\": \"C\"}")
Text item=Test_String_2 label="Virtual String 2 [JSONPATH($.*[?(@.Id=='000005FB25D0')].Temperature):%s]"// returned 3.2 as String
Text item=Test_String_2 label="Virtual String 2 [JSONPATH($..Temperature):%s]"// returned NULL because List.size>1

want ask a question:

I use jsonpath to filter values from a list and return a list, code is like below:

transform(“JSONPATH”,"$…observations…vism", tempJsonRes)
[“5.0”,"-9999.0",“30”, “5.0”, “-9999.0”, “”,“24”,"-9999.0"]

transform(“JSONPATH”,"$…observations[?(@.vism != ‘-9999.0’ && @.vism != ‘’)].vism", tempJsonRes)
[“5.0”,“30”, “5.0”,“24”]

How can I write to get last validated “24” from my json? I want a simple path not using loop.

Please start a new topic for your request. This topic is for discussing the new changes introduced by ESH in the 2.3 snapshots.

I have updated from 2.2.0 to 2.3.0 and now - because of this change - some of my rules are not working anymore. Is there a workaround available for getting the same results as before?

For now I am rolling back to 2.2.0.

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!