Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON Parsing #4943

Closed
orcunbaslak opened this issue Oct 31, 2018 · 2 comments
Closed

JSON Parsing #4943

orcunbaslak opened this issue Oct 31, 2018 · 2 comments
Labels
discussion Topics for discussion

Comments

@orcunbaslak
Copy link

orcunbaslak commented Oct 31, 2018

Hello,

I'm trying to parse a JSON at Telegraf and failing at it.

JSON is like this.

{
  "timestamp": 1541021024224,
  "values": [
    {
      "id": "Raspberry.Pi.Ucuncu",
      "t": 1541021024193,
      "v": 7
    },
    {
      "id": "Raspberry.Pi.Dorduncu",
      "t": 1541021024193,
      "v": 0
    },
    {
      "id": "Raspberry.Pi.Ikinci",
      "t": 1541021024193,
      "v": 4
    },
    {
      "id": "Raspberry.Pi.Birinci",
      "t": 1541021024193,
      "v": 3
    }
  ]
}

and my Telegraf config is like this

#KEPSERVER
[[inputs.mqtt_consumer]]
  servers = ["tcp://localhost:1883"]
  qos = 0
  connection_timeout = "30s"
  topics = [
    "kesy",
  ]
  persistent_session = true
  client_id = "OrcunMQTT"
  data_format = "json"
  name_suffix = "_kesy_vm"

In the json; id will be the tag, t will be the timestamp and v is the value of the tag. timestamp at the top can be ignored.

Any help on this structure is very much appreciated.

Br,

@glinton glinton added the discussion Topics for discussion label Oct 31, 2018
@danielnelson
Copy link
Contributor

@orcunbaslak Try these settings out:

[[inputs.mqtt_consumer]]
  # ... snip...
  json_query = "values"
  tag_keys = ["id"]
  json_time_key = "t"
  json_time_format = "unix_ms"
  data_format = "json"
  fielddrop = ["t"]

@danielnelson
Copy link
Contributor

The fielddrop is needed because the time_key is not removed from the output even after being used. I think this is unwanted behavior so I created #4950.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Topics for discussion
Projects
None yet
Development

No branches or pull requests

3 participants