Can't autodetect fields with json_v2 in flat objects, like json does

The json_v2 plugin can apparently only

  • specify all fields explicitly if they are in the root of the input json
  • specify fields explicitly in nested objects
  • use everything as field in nested objects

But if my input is a flat object (something like {a: 1, b: 2}), I can’t use everything as field automatically and would have to specify a and b explicitly

Is this correct?

Generally, I think your observations are correct. The v2 json parser was meant to be able to explicit define your model and enable nested objects, while the json v1 parser attempts to parse whatever was thrown an it and preferred flat data.

What if I want both? Parse something from a nested object and treat all values in the parent object as fields by default?

Should I open a new feature request on github?

I would take a look at the xpath_json parser, which is even more powerful than the json or json_v2 parser. If you gave an example JSON and what you want your line protocol to look like we might be able to help out.

@sezanzeb sorry for being late to the party, but this is what the XPath parser batch-mode is for. You can then use field_selection = "*" and will get all JSON entries as fields no matter how many or what they are.

The XPath plugin seems to be missing in the plugin directory: Plugin directory | Telegraf 1.27 Documentation

It’s not an input plugin but a parser just as JSON v2. You can find the documentation here.

Ah, I see.

What about this list, json_v2 is there, but not xpath Telegraf input data formats | Telegraf 1.27 Documentation

Hmmm. Not sure where this is generated from. Will check… In the meantime please see https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md