JSON not displaying? Kaitera sensor for example. Check for trailing comma!

41 views
Skip to first unread message

Misza Wolu

unread,
May 17, 2025, 7:33:21 AMMay 17
to Routix

If you're having trouble displaying JSON data, check if there is a trailing comma in your JSON. For example, this JSON is invalid because of the comma after the last item:

{ "ts": 123, "dsn": "321", "data": { "rtemp": 21.86, } }

This trailing comma causes many JSON parsers, including MQTT Dash, to fail when trying to read the data.

Solution: Use JavaScript in the "On Receive" handler to fix the JSON before parsing:

function onReceive(topic, data) { var str = data.toString(); str = str.replace(/,\s*([\]\}])/g, '$1'); // Remove trailing commas before } or ] var obj = JSON.parse(str);

This script cleans the trailing commas and allows MQTT Dash to parse and display your data correctly.

Reply all
Reply to author
Forward
0 new messages