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

parser json return only first element of hashes #5671

Closed
VolJin opened this issue Apr 3, 2019 · 1 comment
Closed

parser json return only first element of hashes #5671

VolJin opened this issue Apr 3, 2019 · 1 comment

Comments

@VolJin
Copy link

VolJin commented Apr 3, 2019

I get only first element of hash and get one metric, but expected more.

Relevant telegraf.conf:

Config:

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

System info:

CentOS Linux release 7.5.1804
telegraf-1.10.2-1.x86_64

Steps to reproduce:

Input:

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

Expected behavior:

Output:

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

Actual behavior:

Output:

file,first=Dale last="Murphy",age=44

Additional info:

but if i check json_query online
He is return array of hashes.
In this example:

[
    {
        "first": "Dale",
        "last": "Murphy",
        "age": 44
    },
    {
        "first": "Roger",
        "last": "Craig",
        "age": 68
    },
    {
        "first": "Jane",
        "last": "Murphy",
        "age": 47
    }
]
@danielnelson
Copy link
Contributor

The option needs to contain a gjson query. From what I can tell, it can't support this transformation, though I am certainly not an expert on everything it can do. We have an existing issue to create a powerful JSON parser (#1363), so I believe this data will have to be part of that request.

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

No branches or pull requests

2 participants