Telegraf, parsing json query

Hi All!
Can I ask for your help, I stuck with parsing JSON with telegraf:

{
  "35998vbNx87fdJHI0@zx1.app.com:1111": {
    "locations": [
      {
        "lat": 43.8841,
        "lon": -79.0607
      },
      {
        "lat": 44.4117,
        "lon": 26.0422
      },
      {
        "lat": 50.458,
        "lon": 30.5303
      },
      {
        "lat": 38.2659,
        "lon": -0.6998
      },
      {
        "lat": 47.0613,
        "lon": 8.3596
      },
      {
        "lat": 38.8078,
        "lon": -77.0523
      },
      {
        "lat": 56.9496,
        "lon": 24.0978
      },
      {
        "lat": 51.5229,
        "lon": -0.202
      },
      {
        "lat": 50.4522,
        "lon": 30.5287
      },
      {
        "lat": 31.0442,
        "lon": 121.4054
      },

I try to use json_query = "35998vbNx87fdJHI0@zx1.app.com:1111"
But no any result in database (influxdb)

Can I ask someone to help me parse this JSON? Maybe I make a stupid mistake, but I really stuck.

Hello @Odmin,
Can you help me by sharing what you expect the line protocol output to look like?
I’d follow this example:

Config:

[[inputs.file]]
  files = ["example"]
  data_format = "json"
  tag_keys = ["first"]
  json_string_fields = ["last"]
  json_query = "obj.friends"

Input:


{
    "obj": {
        "name": {"first": "Tom", "last": "Anderson"},
        "age":37,
        "children": ["Sara","Alex","Jack"],
        "fav.movie": "Deer Hunter",
        "friends": [
            {"first": "Dale", "last": "Murphy", "age": 44},
            {"first": "Roger", "last": "Craig", "age": 68},
            {"first": "Jane", "last": "Murphy", "age": 47}
        ]
    }
}

Output:

file,first=Dale last="Murphy",age=44
file,first=Roger last="Craig",age=68
file,first=Jane last="Murphy",age=47

For something like:
[[inputs.file]]
files = [“example”]
data_format = “json”
json_query = “35998vbNx87fdJHI0@zx1.app.com:1111.locations”

Which would yield:
file lat=31.0442, lon=121.4054
You want to write lat and lons as fields in order not to have runaway cardinality. However your data doesn’t have timestamps associated with each long and lat combination so the final values will overwrite the rest until you addd timestamps.
You coud make the lat and lons as tags but then you don’t have any field values in your data that I can see either.

Hello @Anaisdg
Thanks a lot for your quick response!

Here is my plan:

  1. Collecting JSON data with telegraf and store it in influxdb
  2. Create a dashboard with geomap (Geomap Panel - Native Plugin) and show dots on the map with stored lat/long positions

Unfortunately, I stuck in step 1 right now, hare is my real config:

Config:

[[inputs.http]]
interval = "1m"

 urls = [
     "https://stats.storjshare.io/nodes_geo.json"
   ]

timeout = "60s"

data_format = "json"

json_query = "1wFTAgs9DP5RSnCqKV1eLf6N9wtk4EAtmN5DpSxcs8EjT69tGE@saltlake.tardigrade.io:7777.locations"
name_override = "nodes_geo"
name_prefix = "pub_"

Than I run telegraf for test it:

telegraf --config /etc/telegraf/telegraf_test.conf --test

Output:
2021-09-22T06:50:10Z I! Starting Telegraf 1.19.3

Look like JSON query is not working…

And that’s all, this is my problem and why I asking for help.

Also my expectations about data format:
I would like use 1wFTAgs9DP5RSnCqKV1eLf6N9wtk4EAtmN5DpSxcs8EjT69tGE@saltlake.tardigrade.io:7777.locations like a tag and somehow write lat and lons as fields (you are right), and you a ritgh too about timestamps, I need somehow add it or find a workaround (I just need have data like snapshots with timestamps per day)