I am changing a lot of stuff in my flows and had to distinguish strings from objects coming from mqtt-in.
The "auto-detect (string or buffer)" does not capture JSON.
Looking in the code, the else formats it as a string. Could this be changed to trying to parse it as json first (try/catch) catch would parse it as string:
Just changed it in my running instance, works quite nicely. Although it would be nice to remove the option from the pulldown menu, it would have a lot of implications for existing flows. But the auto-detect/parse of/to json is quite helpful.
I am sure I am not capturing all the exceptions, but I want to eliminate the manual capturing/parsing.
I am talking about the autodetect feature, it should be possible to test whether or not the data is a string, buffer or a json object and if it is the latter send it as a json object. It is a bit redundant to use:
mqtt-in -> json node
in auto-detect mode.
It is an improvement, sometimes you have to break stuff to move forward.
I don't fully understand what you mean here, I thought the data from mqtt could only be a buffer or a string. What do you mean by a json object. By definition JSON is a string.
The option is there to output a parsed JSON object if you want.
That is correct, except that I have to use multiple mqtt nodes and filter/convert its output first.
I have reduced the number of mqtt nodes from 20+ to 1, I see it as an improvement.
Possibly a solution would be to add an option to the dropdown list "Autodetect JSON or string" (or something similar) which attempts to parse a string and returns the object if successful, otherwise returns the string as is.
If I may jump in here I have a terribly naive question. I have a bunch of Sonoff switches running just fine, have their status on Dashboard, etc....
What I cannot figure out is how to parse data received from a Sonoff TH10 (tasmota) device to extract variable data (like temp and humidity). I have looked around and if I've seen it explained, I didn't know it. Here is an example response: