MQTT JSONPath Transformation to extract value from topic "PM2.5"

Hello,

I have an ESP-8266EX with Tasmota and I am reading the values via MQTT. I get the following topic:

'{"Time":"2022-12-14T21:55:36","AM2301":{"Temperature":22.0,"Humidity":56.7,"DewPoint":13.0},"SDS0X1":{"PM2.5":4.6,"PM10":5.0},"TempUnit":"C"}'

With

 transformationPattern="JSONPATH:$.SDS0X1.PM10

I get the correct value of PM10.

But reading PM2.5 does not work with

 transformationPattern=JSONPATH:$.SDS0X1.PM2.5

because of the “.”

How to do it correctly? Thanks a lot!

JSONPATH should accept both . and [ ] forms. So in this case:

JSONPATH:$.SDS0X1[PM2.5]

should work.

when using

JSONPATH:$.SDS0X1[PM2.5]

I get

Executing the JSONPATH-transformation failed: An error occurred while transforming JSON expression.

[ ] is for arrays and I don’t think that’s what we have here. Shouldn’t it be something like the following?

$.SDS0X1.PM2\.5

@liveislife Note the escaped .. . has meaning to JSONPATH and without escaping it I would expect it to fail.

As I understand it, the implementation of JOSNPATH used should accept the bracket notation in general instances too:

However, you may have to put the key in quotes inside the bracket, so perhaps:

JSONPATH:$.SDS0X1['PM2.5']

But, escaping the period should also work.

2 Likes

Finally

JSONPATH:$.SDS0X1['PM2.5']

has worked.

Instead

JSONPATH:$.SDS0X1.PM2\.5

ended with

Configuration model 'mqtt.things' has errors, therefore ignoring it: [6,124]: mismatched character '.' expecting set null [6,149]: mismatched character '<EOF>' expecting '"'

Thank you for your efforts!