Hi I am having the same issue that NCO has when the street name, city or town is missing from the OSM data.
The code is from rtvb (above).
The data is sometimes changed to suburb or district so throws all the data into the text line of the address.
I looked at checking the length of the returned string for each of the JSON transform result and it seems to partially work when the length is >20 I can see the logInfo at this point (restaurant is used as an example).
if(restaurant.length > 20) {
logInfo(“lookupAddress”,“no restaurant”)
val String restaurant = ’ ’
}
2019-01-04 16:57:46.520 [INFO ] [smarthome.model.script.lookupAddress] - no restaurant
However the rule throws an error that the variables are not used in the rule
2019-01-04 16:58:53.947 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model ‘where_am_i.rules’, using it anyway:
The value of the local variable restaurant is not used
and then it puts all of the JSON data in the text string.
2019-01-04 16:57:46.526 [vent.ItemStateChangedEvent] - Address changed from correct address to {“place_id”:“xxxx1761”,“licence”:“Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright",“osm_type”:“way”,“osm_id”:“xxxx6483”,“lat”:“xx.4189xxxx9024”,“lon”:“-x.056xx383674659”,“display_name”:"xxxxx Road, Lxxxxrd, Wxxxl, Nxxxxd, England, xx44 xxJ, United Kingdom”,“address”:{“road”:“xxxxx”,“suburb”:“xxx”,“city”:“xxxx”,“state_district”:“xxxd”,“state”:“England”,“postcode”:“xx44 2BJ”,“country”:“United Kingdom”,“country_code”:“gb”},“boundingbox”:[“xx.4xx636”,“xx.41xx08”,“-x.058xx246”,“-xx.05xx029”]}, xxxxx Road, Wxxx
I need a way to change the incorrect data returned by
val String restaurant = transform(“JSONPATH”, “$.address.restaurant”, result)
to something like
val String restaurant = ‘’
then combine it back to return the address string with a blank value for the road name (or any other that is missing from the JSON transform).
val String address = restaurant + ', ’ + road + ', ’ + city
return address
Is there any quick way to check the JSON transform data is correct and ignore it if returns an error?