Simple correction. It is string1.substring(0,1) Notice the lower case S in substring. If you use the Designer interface you can get what is available by pressing ctrl-space. You would do this right after typing string1.
Ah OK, some kind of scraping. We only know what you tell us.
I’d be looking for a way to extract the JSON from the whole string, i.e. get the string from { to }. I should think a regex would do that, but sorry I am not familiar.
And then use JsonPath. That way, you’d be fairly safe from the data source changing some other details.
There is a nifty string method called .substringBetween
rule "another rule"
when
Item LivingRoom_WallSwitch changed
then
var String myString = "blahblah{\"ip\": \"aaaa\",\"hostname\": \"whatever.com\",\"city\": \"Antartida\",\"region\": \"Low\",\"country\": \"VB\",\"loc\": \"1.1234,1.12345\",\"postal\": \"12345\",\"org\": \"AFDSF\"}"
logInfo("TEST", myString)
var String newString = myString.substringBetween("{","}") //Extract the JSON string between the curly brackets
newString = "{" + newString + "}" // Add the JSON curly brackets back
logInfo("TEST", newString)
var String jsonString = transform("JSONPATH", "$.loc", newString) // Extract the loc value
logInfo("TEST", jsonString) // Display : 1.1234,1.12345
jsonString = transform("JSONPATH", "$.postal", newString) //Extract the postal value
logInfo("TEST", jsonString) // Display: 12345
end