Use MQTT Topic names as database names

Am using telegraf.conf file to connect to 2-3 MQTT topics at a time. How can I use those topic names as my Measurement names in the database when sending data in json format?
I tried using if-else in the conf file but am getting error.

servers = [“localhost:1883”]
##servers = [“”]

MQTT QoS, must be 0, 1, or 2

qos = 0

Topics to subscribe to

topics = [

if [[topics=~“Lenze”]]; then
name_override = “Lenze”
if [[topics=~“DIAG”]]; then
name_override = “DIAG”