When using functions in transform("JSONPATH")
like $.length()
they work just fine. However, I am struggeling with $.append()…
The following code is supposed to add a new “record” to the existing JSON string stored in item vAlarme
var jsonAlarm = "\"" + triggeringItem.name + "\": { \"device\": \"" + alertDevice + "\", \"location\": \"" + alertLocation + "\", \"state\": \"" + newState + "\", \"date\": \"" + now().format(DateTimeFormatter.ofPattern("dd.MM., HH:mm")) + "\"}"
var tmp = transform("JSONPATH", "$.append(jsonAlarm)", vAlarme.state.toString())
vAlarme.sendCommand(tmp)
The output of tmp
however, is not the string to be added but the existing json string to which I want to add a new record.
On the other side, the syntax how I have been using it, makes logically sense.
Before testing around, does anybody know how to use .append()?
EDIT:
most probably the JSON string causes some problems as it is always “converted” when writing to the item. All “:” are being replaced by “=” and all double quotes are deleted.
This is the JSON string stored in vAlarme item:
{"TestItem2": { "device": "ShellyWZSofalampe", "location": "Wohnzimmer", "state": "EASY", "date": "25.02., 14:28"}}
JSON string to be added:
"TestItem": { "device": "ShellyWZSofalampe", "location": "Wohnzimmer", "state": "EASY", "date": "25.02., 14:31"}