Telegraf mqtt fielddrop problems with my usage or understanding

Problem: Telegraf is giving a strconv.ParseFloat error on a field that has been set to be ignored in the telegraf.conf file

Given the following:
An MQTT message with topic name “RSF/TASMOTA/7CC7DC/SENSOR” and json payload of

{
  "Time": "2023-07-22T10:22:32",
  "ANALOG": {
    "A1": 45
  },
  "FLOW": {
    "K": 0.153,
    "Offset": 1.047,
    "FlowPeriod": 0,
    "Rate": 0,
    "RateFactor": 1,
    "VolumeThisFlow": 0,
    "1HrVolume": 0,
    "24HrVolume": 0,
    "Current1HrVolume": 0,
    "Current24HrVolume": 0,
    "FlowUnits": "GPM",
    "VolumeUnits": "GAL",
    "SW-Version": "1.4a",
    "ExcessFlow": false
  }
}

The /etc/telegraf/telegraf.d/local.conf entry for this topic

[[inputs.mqtt_consumer]]
    servers = ["tcp://localhost:1883"]
    qos = 0
    topics = ["RSF/TASMOTA/#",]
    namedrop = ["message*"]
    name_override = "mqtt"
    client_id = ""
    username = ""
    password = ""
    data_format = "json"
    fielddrop = [
    "TypeText",
    "FlowUnits",
    "VolumeUnits",
    "SW-Version",
    "ExcessFlow",
    "Status",
    "Message",
    "SSId",
    "BSSId",
    "Mode",
    "SleepMode",
    "TempUnit"
    ]
    [inputs.mqtt_consumer.tags]
        siteid="rsf01"

I expect the fields listed in “fielddrop” to be ignored. In the /var/log/telegraf/telegraf.log file the following message is displayed:

2023-07-22T18:36:16Z E! [inputs.mqtt_consumer] Error in plugin: strconv.ParseFloat: parsing "0.16,\"FlowUnits\":\"GPM\",\"VolumeUnits\":\"GAL\",\"SW-Version\":\"1.4a\",\"ExcessFlow\":false}}": invalid syntax

I expect that it is something I’ve done wrong, however, any help would be appreciated.

Fielddrop will drop fields at the very end of the input. It does not ignore fields that the parser attempts to read.

The bigger issue is how are you trying to parse your data using the parser? What is your goal? It may make more sense to use the JSON v2 or even xpath_json parsers to parse the data. The JSON parser (non-v2) is only good at flat data.

@dkoneill to get rid of the error, you need to tell the JSON parser to expect the “string” type for those fields, e.g.

  json_string_fields = [
   "TypeText",
    "FlowUnits",
    "VolumeUnits",
    "SW-Version",
    "ExcessFlow",
    "Status",
    "Message",
    "SSId",
    "BSSId",
    "Mode",
    "SleepMode",
    "TempUnit"
  ]