I have a json response which looks like:
{
"tid": "volvo",
"lat": xxx,
"_type": "location",
"t": "p",
"_vehicle": {
"ERS": {
"engineStartWarning": "None",
"timestamp": "2018-05-11T05:22:53+00:00",
"status": "off",
"engineStartWarningTimestamp": "2018-05-11T05:22:53+00:00"
},
"VIN": "xxx",
"assistanceCallSupported": true,
"averageFuelConsumption": 82.0,
"averageFuelConsumptionTimestamp": "2018-05-11T05:24:26+00:00",
"averageSpeed": 74,
"averageSpeedTimestamp": "2018-05-11T05:24:26+00:00",
"bCallAssistanceNumber": "xxx",
"brakeFluid": "Normal",
"brakeFluidTimestamp": "2018-05-11T05:24:26+00:00",
"bulbFailures": [],
"bulbFailuresTimestamp": "2018-05-11T05:24:26+00:00",
"calculatedPosition": {
"longitude": null,
"speed": null,
"timestamp": null,
"heading": null,
"latitude": null
},
I would like to extract “heading”
With JSONPATH I used:
val String head = transform("JSONPATH", "$._vehicle.calculatedPosition.heading", json)
However, this returns " null"
I would prefer “null”
I also tried with REGEX:
val String head = transform(“REGEX”, ““calculatedPosition”: {\s.,\s.,\s.,\s.“heading”: (.*),”, json)
Which works in an online REGEX tester, but not in OH:
Configuration model 'car.rules' has errors, therefore ignoring it: [63,55]: Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\ )
Any suggestion to solve this the best way?
I could use " null" in rules - but that’s kind of “dirty”