JSON Path Info
When parsing simple JSON data that is part of a topic you can parse them without scripting by entering the path to the data into this field after checking the Parse Payload as JSON checkbox.
Enter the path through the JSON object to find the data field you wish to process. The processing of that value will be the same as the selected Unit type would process a plain text or numerical value. Each key or index into the JSON object must be separated by a backslash character. This means that if the keys have a backslash in them you cannot parse that this way. Let me know if you need an escape sequence for that and I’ll add the ability in a future version.
Note that JSON keys are case sensitive
As the simplest example here is a JSON object with a single value showing a temperature:
{“Current Temp”:”15.3C”}
the path to pull this value would be just the key “Current Temp” no slashes needed like:
Current Temp
Any number of JSON dictionaries may be traversed like that. Here is an example with multiple layers:
{“Super Sensor Values”:{temperature:{“scale”:”F”, “value":76}}}
in this case to get to the value in C the path to the value would be:
Super Sensor Values/temperature/value
You can also parse JSON payloads with arrays as well as dictionaries. If the parser encounters an array it will expect the value in the parsing path to be an integer telling it which number to pull for further parsing.
An example might be something that sends several sensor values in a single Dictionary entry like:
{“sensors”:[ {“name”:”fridge”, “type”:”hum”, “value”:32}, {“name”:”fridge”, “type”:”temp”, “value”:39}, {“name”:”outside”, “type”:”temp”, “value”:69} ] }
Note that indexes into arrays start at 1 and not 0. So the path to get the outside temperature would be:
sensors/3/value
Note that there is currently no way to walk an array looking for a specific field in one of the array members. Let me know if this is something you need to do and I can find a way to make the path handle that too.
Some Real Life Examples:
To parse data from a real life example of a Tasmota sensor with an output something like this:
{"Time":"2023-02-11T12:22:21","SI7023":{"Temperature":23.1,"Humidity":43.2,"DewPoint":9.9},"TempUnit":”C”}
The path to get the Temperature would be:
SI7023/Temperature
Since you can create multiple units all pointed to the same Topic Path if you wished to have a Unit for all three values in the above just create 3 Units with the same Topic Path, but with the appropriate JSON path to get the different values. “SI7023/Temperature”, “SI7023/Humidity”, and “SI7023/DewPoint“