Ignore UTF8 BOM in JSON parser (#4099)

This commit is contained in:
Daniel Meiners
2018-05-03 20:40:28 +02:00
committed by Daniel Nelson
parent c1d4b0b154
commit 9647ea88ea
2 changed files with 17 additions and 0 deletions

View File

@@ -12,6 +12,10 @@ import (
"github.com/influxdata/telegraf/metric"
)
var (
utf8BOM = []byte("\xef\xbb\xbf")
)
type JSONParser struct {
MetricName string
TagKeys []string
@@ -68,6 +72,7 @@ func (p *JSONParser) parseObject(metrics []telegraf.Metric, jsonOut map[string]i
func (p *JSONParser) Parse(buf []byte) ([]telegraf.Metric, error) {
buf = bytes.TrimSpace(buf)
buf = bytes.TrimPrefix(buf, utf8BOM)
if len(buf) == 0 {
return make([]telegraf.Metric, 0), nil
}