Hook up json_strict option with default of true (#6909)
This commit is contained in:
parent
5f1f4b9e8d
commit
c6519c7793
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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")
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue