update DATA_FORMATS_INPUT.md to reflect gjson

This commit is contained in:
Max U
2018-07-02 14:56:31 -07:00
parent 9836b1eb02
commit b09fcc70c8
2 changed files with 81 additions and 0 deletions

View File

@@ -29,21 +29,37 @@ func (j *JSONPath) Parse(buf []byte) ([]telegraf.Metric, error) {
for k, v := range j.TagPath {
c := gjson.GetBytes(buf, v)
if c.IsArray() {
log.Printf("E! GJSON cannot assign array to field on path: %v", v)
continue
}
tags[k] = c.String()
}
for k, v := range j.FloatPath {
c := gjson.GetBytes(buf, v)
if c.IsArray() {
log.Printf("E! GJSON cannot assign array to field on path: %v", v)
continue
}
fields[k] = c.Float()
}
for k, v := range j.IntPath {
c := gjson.GetBytes(buf, v)
if c.IsArray() {
log.Printf("E! GJSON cannot assign array to field on path: %v", v)
continue
}
fields[k] = c.Int()
}
for k, v := range j.BoolPath {
c := gjson.GetBytes(buf, v)
if c.IsArray() {
log.Printf("E! GJSON cannot assign array to field on path: %v", v)
continue
}
if c.String() == "true" {
fields[k] = true
} else if c.String() == "false" {
@@ -55,6 +71,10 @@ func (j *JSONPath) Parse(buf []byte) ([]telegraf.Metric, error) {
for k, v := range j.StrPath {
c := gjson.GetBytes(buf, v)
if c.IsArray() {
log.Printf("E! GJSON cannot assign array to field on path: %v", v)
continue
}
fields[k] = c.String()
}