Configuring Telegraf to use dynamic measurement_name_path

I am trying to configure Telegraf based on the following JSON I receive from a MQTT broker -

{
“unitFactoryNumber”: “0123-012345-012345”,
“timestamp”: 1696338745,
“checksum”: “118fe7677cb766bdc7630c2347763bc4”,
“data”: [{
“id”: 23831,
“v”: 0
}, {
“id”: 23801,
“v”: 21.2
}, {
“id”: 23800,
“v”: 21.1
}, {
“id”: 23431,
“v”: 0
}, {
“id”: 23409,
“v”: 0
}, {
“id”: 23407,
“v”: 0
}
],
“deviceID”: “device-12345”
}

The bucket name is the “unitFactoryNumber” attribute. Each “id” attribute should be a measurement within the bucket. The “v” attribute and the “timestamp” attribute should be the fields for each measurement. What should the telegraf.conf look like for this? I have tried a few variations with no success so far. Example -

[[outputs.influxdb_v2]]
urls = [“…”]
token = “…”
organization = “…”
bucket_tag = “unitFactoryNumber”
exclude_bucket_tag = true

[[inputs.mqtt_consumer]]
servers = [“…”]
topics = [
“…”
]
data_format = “json_v2”
[[inputs.mqtt_consumer.json_v2]]
measurement_name_path = “rid”
[[inputs.mqtt_consumer.json_v2.object]]
path = “@this
tags = [“unitFactoryNumber”]
[inputs.mqtt_consumer.json_v2.object.renames]
timestamp = “sampleTime”
[[inputs.mqtt_consumer.json_v2.object]]
path = “data”
[inputs.mqtt_consumer.json_v2.object.renames]
id = “rid”
v = “sampleValue”

I would use the xpath parser for this:

[[outputs.influxdb_v2]]
  urls = [“…”]
  token = “…”
  organization = “…”
  bucket_tag = “bucket”
  exclude_bucket_tag = true

[[inputs.mqtt_consumer]]
  servers = [“…”]
  topics = [
    “…”
  ]
  data_format = "xpath_json"
  xpath_native_types = true

  [[inputs.mqtt_consumer.xpath]]
    metric_name = "'mymetric'"
    metric_selection = "//data/*"
    timestamp = "/timestamp"
    timestamp_format = "unix"

    [inputs.mqtt_consumer.xpath.fields]
      id = "id"
      value = "v"

    [inputs.mqtt_consumer.xpath.tags]
      bucket = "/unitFactoryNumber"
      device = "/deviceID"

However, this will produce the metrics

> mymetric,bucket=0123-012345-012345,device=device-12345,host=Hugin id=23831,value=0 1696338745000000000
> mymetric,bucket=0123-012345-012345,device=device-12345,host=Hugin id=23801,value=21.2 1696338745000000000
> mymetric,bucket=0123-012345-012345,device=device-12345,host=Hugin id=23800,value=21.1 1696338745000000000
> mymetric,bucket=0123-012345-012345,device=device-12345,host=Hugin id=23431,value=0 1696338745000000000
> mymetric,bucket=0123-012345-012345,device=device-12345,host=Hugin id=23409,value=0 1696338745000000000
> mymetric,bucket=0123-012345-012345,device=device-12345,host=Hugin id=23407,value=0 1696338745000000000

which all belong to the same series at the same timestamp. So only the last entry will survive in the database. You need to differentiate the series so probably make id a tag or similar…

Thank you for your answer. We have now changed our approach of consuming the data, and the issue is resolved.