JSONPath Transformation get string not number

Hi,
I’m getting some data via HTTP Binding and because json is returned I’m trying to get a temperature as a number using JSONPath Transformation.

The HTTP server is returning the following string:
{“software_version”: “NRZ-2017-099”, “age”:“5”, “sensordatavalues”:[{“value_type”:“SDS_P1”,“value”:“49.50”},{“value_type”:“SDS_P2”,“value”:“27.90”},{“value_type”:“BME280_temperature”,“value”:“8.60”},{“value_type”:“BME280_humidity”,“value”:“72.96”},{“value_type”:“BME280_pressure”,“value”:“93340.02”},{“value_type”:“samples”,“value”:“607281”},{“value_type”:“min_micro”,“value”:“233”},{“value_type”:“max_micro”,“value”:“26572”},{“value_type”:“signal”,“value”:"-77"}]}

I’m needing the BME280 Temperature so I’m having the item that does not work:
Number air1_temp { http="<[air1:10000:JSONPATH($.sensordatavalues[?(@.value_type==‘BME280_temperature’)].value)]" }

Then I figure out that the JSONPath Transformation is returning a sting not a number so if I changed the item to string and this is what I’m getting:
2017-11-08 00:41:33.781 [ItemStateChangedEvent ] - air1_temp changed from [“8.70”] to [“8.60”]

So how can I change the JSONPath in order to get only the number 8.60 but not [“8.60”]

Thanks

@ddragoev you need two items one to save the string and one to hold the converted number, use a rule for that.

have a look at this discussion

Thank you for the update Josar. I’ve change a little but the rule as the string is [“8.60”] so now I have:

Items:
String air1_temp_s { http="<[air1:60000:JSONPATH($.sensordatavalues[?(@.value_type==‘BME280_temperature’)].value)]" }
Number air1_temp “Outside Temperature [%.1f °C]”

Rule:
rule “Update Temp"
when
Item air1_temp_s received update
then
air1_temp.postUpdate(air1_temp_s.state.toString.replace(’”’,’’).replace(’[’,’’).replace(’]’,’’))
end

Not so nice but it’s working :smile:

Hi,

I have a very similar use case - i.e. I want to link a Number item to a HTTP binding that retrieves a JSON response, but the JSONPath transformation only returns a string.

Is a rule as described above still the best method? Or is there a simpler / nicer method available now?

How would I create the rule (to update the Number item based on the value of the String item) in the UI?

Thanks!

Welcome to the forum.

There should be no problem with sending a string from the JSONpath transform to a number item. If it is not working for you then there is something wrong with the output of the transform.

Instead of adding on to a 6 year-old conversation, you should create a new thread with all the information you can add related to your question. Show the JSONpath you are using, show the item definition, show an example or two of the JSON response you are trying to parse, show any log lines related to the issue. The problem could lie anywhere and the more information you provide, the more likely someone can find the issue for you.