Skip to content

json_query not parsing through all entries in the JSON array #6138

@harnitsignalfx

Description

@harnitsignalfx

Hi, I think there is a bug in how JSON array entries are being parsed by JSONQuery. Would really appreciate guidance on whether I've made a configuration error or this is indeed reproducible by other folks.

Relevant telegraf.conf:

[[inputs.tail]]
  files = ["/test.log"]
  watch_method = "poll"
  data_format = "json"
  name_override = "test-key"
  tag_keys = ["first"]
  json_query = "friends"

System info:

Telegraf v 1.11.2
OS: Debian 9

Steps to reproduce:

  1. Follow the example for JSON Query -
    https://github.com/influxdata/telegraf/tree/master/plugins/parsers/json#query
    So a sample entry in the file would be -
{"friends": [{"first": "Dale", "last": "Murphy", "age": 44},{"first": "Roger", "last": "Craig", "age": 68},{"first": "Jane", "last": "Murphy", "age": 47}]}

Expected behavior:

All entries in the array are parsed (very similar to the posted example)

{"fields":{"age":44},"name":"test-key","tags":{"first":"Dale","host":"test-us1-instance","path":"/test.log"},"timestamp":1563466236}
{"fields":{"age":68},"name":"test-key","tags":{"first":"Roger","host":"test-us1-instance","path":"/test.log"},"timestamp":1563466236}
{"fields":{"age":47},"name":"test-key","tags":{"first":"Jane","host":"test-us1-instance","path":"/test.log"},"timestamp":1563466236}

Actual behavior:

Only the first array entry is being parsed.
{"fields":{"age":44},"name":"test-key","tags":{"first":"Dale","host":"test-us1-instance","path":"/test.log"},"timestamp":1563466236}

Metadata

Metadata

Assignees

Labels

area/tailbugunexpected problem or unintended behavior

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions