JSONPATH transformation in item

I’m configuring JSONPATH transformation for the first time and seems to be missing something basic. Please advise.
This is the item:
String Sonoff1info "Sonoff #1 startup info [%s]" { mqtt="<[broker:tele/sonoff1/RESULT:state:JSONPATH($.Info1.Version)]" }

And this is the raw JSON received from the broker:
{"Info1":{"AppName":"Sonoff 8266 Module", "Version":"3.2.13", "FallbackTopic":"DVES_XXXXXX", "GroupTopic":"sonoffs"}}

My goal is to extract:
a) single value like "3.2.13"
b) name with value like “Version”:"3.2.13"
c) the whole string like it was before the firmware author switched to JSON

At the moment I’m getting:
[WARN ] [pse.smarthome.core.items.GenericItem] - failed notifying listener '[org.eclipse.smarthome.core.persistence.internal.PersistenceManagerImpl@ee100e1, Sonoff1info, null]' about state update of item java.lang.NullPointerException: {}

have you tried

String	Sonoff1info "Sonoff #1 startup info [%s]" { mqtt="<[broker:tele/sonoff1/RESULT:state:default]" }

and do you see the complete message in the item?

1 Like

Yes, but… Here is the thing - in fact I’m getting 2 responses:

tele/sonoff1/RESULT {"Info1":{"AppName":"Sonoff 8266 Module", "Version":"3.2.13", "FallbackTopic":"DVES_XXXXXX", "GroupTopic":"sonoffs"}}
tele/sonoff1/RESULT {"Info2":{"WebserverMode":"Admin", "Hostname":"sonoff1-XXXX", "IPaddress":"192.168.X.X"}}

Without transform I see the 2nd result only.

You migh have success getting only from the message containing Info1 if you use the optional REGEX filter documented here.

Do you mean REGEX instead of JSONPATH or in addition to JSONPATH?

In addition to. It’s an optional additional section after the transform.

No error and no update of the item. Added per example from the docs:
String Sonoff1info "Sonoff #1 startup info [%s]" { mqtt="<[broker:tele/sonoff1/RESULT:state:JSONPATH($.Info1.Version):REGEX(.*\"Info1\".*)]" }

Oops, works without REGEX word.
Thanks!

1 Like

So this worked?

String	Sonoff1info "Sonoff #1 startup info [%s]" { 
  mqtt="<[broker:tele/sonoff1/RESULT:state:JSONPATH($.Info1.Version):.*\"Info1\".*]" 
}

Yes, this works, but I was not able to harden the filter by checking for leading {
Constructions like \{*\"Info1\".* or .*\{\"Info1\".*are not working, but I can live with this.

Currently I can grab the individual values as well as the whole string by using JSONPATH($.Info1)

{AppName=Sonoff 8266 Module, Version=3.2.13, FallbackTopic=DVES_XXXXXXX, GroupTopic=sonoffs}
How can I get rid of {} ?