I’m out of ideas out to parse my simple Json data in Telegraf
I have this file
{
"inc_code": "I1",
"sensors": [
{
"n": 1,
"aX": 12
},
{
"n": 2,
"aX": 50
}
]
}
and my expected output in telegraf is
I1, n=1 aX=12
I1, n=2 aX=50
How should be the telegraf.com file?
I’ve tried
[[inputs.mqtt_consumer.json_v2]]
measurement_name_path = "inc_code"
[[inputs.mqtt_consumer.json_v2.tag]]
path = "sensors.#.n"
[[inputs.mqtt_consumer.json_v2.field]]
path = "sensors.#.aX"
type = "float"
which results in
I1,n=1 aX=12 1690565287967408422
I1,n=1 aX=50 1690565287967408422
I1,n=2 aX=12 1690565287967408422
I1,n=2 aX=50 1690565287967408422
Where is a duplication of the values. I don’t need lines two and three!
Any ideas?
Looked at all examples and concluded that The following setup solves it, but i dont understand it.
Can anyone explain me why it works?
[[inputs.file.json_v2]]
measurement_name_path = “inc_code”
[[inputs.file.json_v2.object]]
disable_prepend_keys = true
path = “@this”
tags = [“sensors_n”]
The output
I1, n=1 aX=12
I1, n=2 aX=50
In particular i dont understand the function of
path = “@this”
sensors_n underscore why?
What docs did you use? I refer to the one on GitHub
@this
: Returns the current element. It can be used to retrieve the root element. (docs here)
tags = [“sensors_n”]
for a nested key, prepend the parent keys with underscores, therefore it just navigates from the path to the key, _
should be the separator sensors_n = CurrentPath -> sensors -> n
I’ve read that.
But in my case in path using
“@this”
Or
“sensors”
Should not result in the same output?
Not sure if I understand the difference between . and _
Anyway it works now