Chaining MAP to JSONPATH does not work

Hi
I am creating a sitemap where a Text item has to show the status of an alarm contact received via MQTT
Messages are like this

{"TYPE": "ZON", "A": "N", "STA": "R"}

The sitemap definition using only JSONPATH works well.
Then I have introduced a map file named “statizone.map” placed under the usual /transform folder:

A=ALLARME
R=RIPOSO

Then I configured the sitemap like this

sitemap alarmapp label="Alarm App Test" {
    Frame label="Zone" {
        Text item=zona_5 label="Zona 5 [JSONPATH($.STA)∩MAP(statizone.map):%s]"
    }
}

With this mapping i get exceptions in the log file: looks like the chained mappings are not parsed well by the interpreter.

org.eclipse.smarthome.core.transform.TransformationException: An error occurred while transforming JSON expression.
        at org.openhab.transform.jsonpath.internal.JSonPathTransformationService.transform(JSonPathTransformationService.java:75) ~[?:?]
        at org.eclipse.smarthome.ui.internal.items.ItemUIRegistryImpl.transform(ItemUIRegistryImpl.java:537) [bundleFile:?]
        at org.eclipse.smarthome.ui.internal.items.ItemUIRegistryImpl.getLabel(ItemUIRegistryImpl.java:449) [bundleFile:?]
        at org.eclipse.smarthome.io.rest.sitemap.internal.PageChangeListener.constructSitemapEvents(PageChangeListener.java:228) [bundleFile:?]
        at org.eclipse.smarthome.io.rest.sitemap.internal.PageChangeListener.constructSitemapEvents(PageChangeListener.java:214) [bundleFile:?]
        at org.eclipse.smarthome.io.rest.sitemap.internal.PageChangeListener.constructAndSendEvents(PageChangeListener.java:172) [bundleFile:?]
        at org.eclipse.smarthome.io.rest.sitemap.internal.PageChangeListener.stateChanged(PageChangeListener.java:186) [bundleFile:?]
        at org.eclipse.smarthome.core.items.GenericItem$1.run(GenericItem.java:261) [bundleFile:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_144]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_144]
        at java.lang.Thread.run(Thread.java:748) [?:1.8.0_144]
Caused by: com.jayway.jsonpath.InvalidPathException: Arguments to function: 'STA)∩MAP' are not closed properly.
        at com.jayway.jsonpath.internal.path.PathCompiler.parseFunctionParameters(PathCompiler.java:375) ~[?:?]
        at com.jayway.jsonpath.internal.path.PathCompiler.readPropertyOrFunctionToken(PathCompiler.java:217) ~[?:?]
        at com.jayway.jsonpath.internal.path.PathCompiler.readNextToken(PathCompiler.java:151) ~[?:?]
        at com.jayway.jsonpath.internal.path.PathCompiler.readDotToken(PathCompiler.java:171) ~[?:?]
        at com.jayway.jsonpath.internal.path.PathCompiler.readNextToken(PathCompiler.java:145) ~[?:?]
        at com.jayway.jsonpath.internal.path.PathCompiler.readContextToken(PathCompiler.java:124) ~[?:?]
        at com.jayway.jsonpath.internal.path.PathCompiler.compile(PathCompiler.java:58) ~[?:?]
        at com.jayway.jsonpath.internal.path.PathCompiler.compile(PathCompiler.java:75) ~[?:?]
        at com.jayway.jsonpath.JsonPath.<init>(JsonPath.java:101) ~[?:?]
        at com.jayway.jsonpath.JsonPath.compile(JsonPath.java:467) ~[?:?]
        at com.jayway.jsonpath.internal.JsonContext.read(JsonContext.java:87) ~[?:?]
        at com.jayway.jsonpath.JsonPath.read(JsonPath.java:502) ~[?:?]
        at org.openhab.transform.jsonpath.internal.JSonPathTransformationService.transform(JSonPathTransformationService.java:63) ~[?:?]
        ... 10 more

Any suggestion? Is it a bug or I use the wrong syntax?
Thanks for help

Item labels simply do not support chaining of transforms.

So far as I know, the only place in openHAB that does support chaining is the MQTT binding.

Is there some reason you are not parsing the JSON field out at the binding channel into an Item?

Hi rossko57
Thank you for your answer. This explains all.
Well, I actually tried to do as you write: I have set the definition (which I do not recall now) into the Generic MQTT Thing’s channel transformation field using the Paper UI, but I got exceptions as well.
I will give it another try and post here the result.

Hi rossko57
Well, yes, it is working now.
The string “JSONPATH:$.STA∩MAP:statizone.map” in the channel’s transformation does the job.
Thank you!!

1 Like