I am trying to ingest data from an MQTT source that sends everything as strings (which I can’t change):
{"dateTime": "1752936484.0", "usUnits": "1.0", "maxSolarRad_Wpm2": "844.9766676993108", "rainRate_inch_per_hour": "0.0", "beaufort_count": "2.0", "hourRain_in": "0.0", "rain24_in": "0.0", "dayRain_in": "0.0", "rainSize_in": "0.01", "rainCountRate_per_hour": "0.0", "windDir": "139.0", "windSpeed_mph": "6.18", "windGust_mph": "6.18", "windGustDir": "139.0", "rainCount_count": "0.0", "rain_in": "0.0"}
My telegraf.conf looks like this:
[[inputs.mqtt_consumer]]
servers = ["tcp://localhost:1883"]
topics = ["weather/#"]
data_format = "json_v2"
[[inputs.mqtt_consumer.json_v2]]
measurement_name = "observation" # A string that will become the new measurement name
timestamp_path = "dateTime" # A string with valid GJSON path syntax to a valid timestamp (single value)
timestamp_format = "unix" # A string with a valid timestamp format (see below for possible values)
[[inputs.mqtt_consumer.json_v2.object]]
path = "@this"
Is there a way to convert every value of every field to float? I can convert each field manually using [inputs.file.json_v2.object.fields]
but I’d love to have a way to do it for all strings.