I can't write a field in InfluxDB

I receive a record from Kafka in JSON as the following example:

{
“measurement”: “serialized”,
“time”: 1710794594123456789,
“component”: “22”,
“field”: “acc_x”,
“value”: 33.77
}

The “field” field is generic and will vary depending on the Kafka record.
The “value” field is the value of the “field”.
The “component” field is the tag.

I want to write to InfluxDB according to the example converted into InfluxDB line protocol:

serialized,component=22 acc_x=33.77 1710794594123456789

// Syntax
[,<tag_key>=<tag_value>[,<tag_key>=<tag_value>]] <field_key>=<field_value>[,<field_key>=<field_value>] []

I tried several configurations in the telegraf.conf file.
None of them worked.

You can use the xpath_json parser for the job:

[[inputs.kafka_consumer]]
  precision = "1ns"

  ...

  data_format = "xpath_json"
  xpath_native_types = true

  [[inputs.kafka_consumer.xpath]]
    metric_name = "/measurement"
    timestamp = "/time"
    timestamp_format = "unix_ns"
    field_selection = "/value"
    tag_selection = "/component"
    field_name = "/field"

resulting in

> serialized,component=22,host=Hugin acc_x=33.77 1710794594123456768

for your example…

It worked. Thank you.