I’ve just upgraded my second Pi to OH2, and I can no longer get rid of the square bracket with JSONPATH.
I get this from an APi query
[{"acState":{"on":false,"fanLevel":"auto","temperatureUnit":"C","targetTemperature":20,"mode":"cool","swing":"rangeFull"},"measurements":{"batteryVoltage":2989,"temperature":21.6,"humidity":67.7,"time":{"secondsAgo":27,"time":"2017-04-12T03:20:04Z"},"rssi":-75,"piezo":[null,null]},"room":{"name":"Office","icon":"lounge"},"id":"myID"}]
I then add
var String HeatpumpOn = (transform("JSONPATH", "$..on",HPStatus))
which gives me
[false]
when I actually want
false
in OH 1.8 I used
var String HeatpumpOn = (transform("JSONPATH", "$..on[0]", HPStatus))
which worked, however with OH 2.0 I get a blank result. I believe JSONPATH has been updated which explains the change, but a considerable amount of googling hasn’t given me the new way of doing things.
Can anyone give me a clue what the correct syntax should be?
I could use an extra step such as this, but is there a better way?
val String CleanedString = (HeatpumpOn.replace('[', '').replace(']', ''))