MQTT Parse Error: JSON with string tag_keys

I’m pretty new to telegraf so be gentle. :slight_smile:

I’m trying to parse some JSON from MQTT messages that look like this:

{"temperature":"48.92","humidity":"60.30"}

My config file’s relevant sections look like this:

   data_format = "json"

   tag_keys = [ 
     "temperature",
     "humidity"
   ]

However I am getting the below error message:

2018-02-26T00:37:18Z E! Error in plugin [inputs.mqtt_consumer]: E! MQTT Parse Error
message: {"temperature":"48.92","humidity":"60.30"}
error: mqtt_consumer: must have one or more fields

What am I doing wrong?

You will need at least one numeric type to use as a value, but in this case you probably want both temperature and humidity to be numeric. Are you able to change the JSON to encode these items as floats and remove them from the tag_keys?

Oh - interesting!

So there must be a numeric value in the JSON even if both keys are in the tag_keys array?

That’s interesting. Happen to know if there is already an enhancement request for this? I may be able to change the JSON but it seems like this use case isn’t uncommon.

Had the same problem.
Assuming you used the code from here, this is what worked for me:
Change codelines

root[“temperature”] = (String)p_temperature;
root[“humidity”] = (String)p_humidity;

to

root[“temperature”] = p_temperature;
root[“humidity”] = p_humidity;

and comment out (or delete) the tag_keys block in you telegraf config.

1 Like

Happen to know if there is already an enhancement request for this?

There are a few related issues open:

Whoa - that’s some serious detective work there! How did you know?

I’ll try that out and follow up.

I got exact the same JSON output, so I took a guess :sweat_smile: