How to configure Telegraf to parse MQTT with JSON message

Hi,
I am at the beginning of the learning curve how to configure Telegraf for my needs. Till now I have successfully configured to receive MQTT datas from my wallbox for normal values. But the box also publish some datas combined in a JSON String.
Within the MQTT Explorer the String looks like this:

The Value of the JSON-String for the config topic is as follows:

{“average_consumption”: 18000, “charge_template”: 1, “chargemode”: “pv_charging”, “current_plan”: null, “ev_template”: 1, “priority”: false, “time_charging_in_use”: false}

How can I extract for example the chargemode value?

My telegraf.conf:

[agent]
  interval = "10s"
  round_interval = true
  metric_batch_size = 1000
  metric_buffer_limit = 10000
  collection_jitter = "0s"
  flush_interval = "10s"
  flush_jitter = "0s"
  precision = "0s"
  debug = false
  logtarget = "file"
  logfile = "/var/log/telegraf/telegraf.log"
  hostname = ""
  omit_hostname = false

###############################################################################
#                            OUTPUT PLUGINS                                   #
###############################################################################

[[outputs.influxdb]]
	urls = ["http://127.0.0.1:8086"]
	database = "telegraf"

###############################################################################
#                            SERVICE INPUT PLUGINS                            #
###############################################################################

# # Read metrics from MQTT topic(s)
[[inputs.mqtt_consumer]]
servers = ["tcp://10.10.20.12:1883"]
#
#   ## Topics that will be subscribed to.
topics = [
     "openWB/chargepoint/get/#",
	 "openWB/chargepoint/1/get/#",
	 "openWB/vehicle/2/get/#",
   ]
client_id = "TelegrafOpenWB"
data_format = "value"
# data_type = "float"
data_type = "string"
#
#   ## Enable extracting tag values from MQTT topics
#   ## _ denotes an ignored entry in the topic path
	[[inputs.mqtt_consumer.topic_parsing]]
		topic = "openWB/chargepoint/1/get/+"
   		measurement = "chargemode"
#   #   tags = ""
#   #   fields = ""
#   ## Value supported is int, float, unit
#   #   [[inputs.mqtt_consumer.topic.types]]
#   #      key = type

Which is not working for me. I receive all the topics and values but I can not separate all the informations from the JSON-Sttring.

Regards Chris

Hello @ChrisChros,
Have you tried using:
data_format = "json_v2"
Docs:

Let me know if that helps!

As Anaisdg already mentioned you will want to look at the json_v2 format parser to parse your JSON value. With that you can pull out the tags and fields you are interested in, rather than getting a JSON string.

Because your JSON is flat, you could also consider the json format parser and specify a string field:

  data_format = "json"
  json_string_fields = ["chargemode"]

If your data becomes any more complex though, you would want to look at the json_v2 or even the xpath parsers.

Thanks for the two suggestions, I will try to implement this into my config. I will give a feedback as soon as possible.