Skip to content

Commit

Permalink
Hook up json_strict option with default of true (influxdata#6909)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielnelson authored Jan 21, 2020
1 parent c6253e1 commit 8fd2845
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
17 changes: 16 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1411,7 +1411,9 @@ func buildParser(name string, tbl *ast.Table) (parsers.Parser, error) {
}

func getParserConfig(name string, tbl *ast.Table) (*parsers.Config, error) {
c := &parsers.Config{}
c := &parsers.Config{
JSONStrict: true,
}

if node, ok := tbl.Fields["data_format"]; ok {
if kv, ok := node.(*ast.KeyValue); ok {
Expand Down Expand Up @@ -1512,6 +1514,18 @@ func getParserConfig(name string, tbl *ast.Table) (*parsers.Config, error) {
}
}

if node, ok := tbl.Fields["json_strict"]; ok {
if kv, ok := node.(*ast.KeyValue); ok {
if b, ok := kv.Value.(*ast.Boolean); ok {
var err error
c.JSONStrict, err = b.Boolean()
if err != nil {
return nil, err
}
}
}
}

if node, ok := tbl.Fields["data_type"]; ok {
if kv, ok := node.(*ast.KeyValue); ok {
if str, ok := kv.Value.(*ast.String); ok {
Expand Down Expand Up @@ -1808,6 +1822,7 @@ func getParserConfig(name string, tbl *ast.Table) (*parsers.Config, error) {
delete(tbl.Fields, "json_time_format")
delete(tbl.Fields, "json_time_key")
delete(tbl.Fields, "json_timezone")
delete(tbl.Fields, "json_strict")
delete(tbl.Fields, "data_type")
delete(tbl.Fields, "collectd_auth_file")
delete(tbl.Fields, "collectd_security_level")
Expand Down
1 change: 1 addition & 0 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ func TestConfig_LoadDirectory(t *testing.T) {
p, err := parsers.NewParser(&parsers.Config{
MetricName: "exec",
DataFormat: "json",
JSONStrict: true,
})
assert.NoError(t, err)
ex.SetParser(p)
Expand Down
2 changes: 1 addition & 1 deletion plugins/parsers/json/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ignored unless specified in the `tag_key` or `json_string_fields` options.

## When strict is true and a JSON array is being parsed, all objects within the
## array must be valid
strict = false
json_strict = true

## Query is a GJSON path that specifies a specific chunk of JSON to be
## parsed, if not specified the whole document will be parsed.
Expand Down

0 comments on commit 8fd2845

Please sign in to comment.