Write data despite missing tag value

Hi,
I’m using Telegraf with the MQTT-Input-Plugin to write data to an InfluxDB.
I’m parsing the input from the MQTT-source as JSON.

Here is a part of my configuration conf-file:

[[inputs.mqtt_consumer.json_v2]]
	[[inputs.mqtt_consumer.json_v2.tag]]
    	path = "deviceName"

    [[inputs.mqtt_consumer.json_v2.tag]]
    	path = "devEUI"		
    
	[[inputs.mqtt_consumer.json_v2.tag]]
    	path = "tags.location"		

	[[inputs.mqtt_consumer.json_v2.tag]]
    	path = "tags.municipality"		

	[[inputs.mqtt_consumer.json_v2.tag]]
    	path = "tags.sensortype"	

The tags “tags.location”, “tags.municipality” and “tags.sensortype” in the source data are in the end from manual inputs when registering sensors. So they might be missing, when some forget to put in a value. Still the sensors will send data that I want to write into the database.
But Telegraf dismisses the complete data set, when one of the configured tags is missing.
Is there a way to force Telegraf to still write the data, though one of the tags is missing?
Would be fine for me to write the missing tag as “” or “null” or whatever.

To solve this, you can use a processor plugin in Telegraf to set default values for missing tags. The defaults processor is perfect for this.

Here’s how you can modify your configuration:

[[inputs.mqtt_consumer.json_v2]]
  [[inputs.mqtt_consumer.json_v2.tag]]
    path = "deviceName"
  
  [[inputs.mqtt_consumer.json_v2.tag]]
    path = "devEUI"
  
  [[inputs.mqtt_consumer.json_v2.tag]]
    path = "tags.location"
  
  [[inputs.mqtt_consumer.json_v2.tag]]
    path = "tags.municipality"
  
  [[inputs.mqtt_consumer.json_v2.tag]]
    path = "tags.sensortype"

# Add this processor to handle missing tags
[[processors.defaults]]
  [processors.defaults.tags]
    location = "unknown"
    municipality = "unknown" 
    sensortype = "unknown"

If some of these tags are actually required for your data to make sense, you might want to use more specific default values or set up alerting to notify you when tags are missing.