Skip to content

funcr: invalid json when omitting fields #157

@edebernis

Description

@edebernis

Hello !

When using funcr implementation with JSON formatter, produced JSON is invalid when omitting fields using json struct tag.

How to reproduce

Go Playground

type Foo struct {
	Bar string `json:"-"`
	Baz string `json:"baz"`
}

func main() {
	logger := funcr.NewJSON(
		func(obj string) { fmt.Println(obj) },
		funcr.Options{},
	)
	logger.Info("", "foo", Foo{})
}

Expected output

{"logger":"","level":0,"msg":"","foo":{"baz":""}}

Got output

{"logger":"","level":0,"msg":"","foo":{,"baz":""}}

Notice the extra comma before baz key.

A quick investigation pointed this line as the potential issue.

Thanks for your help !

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions