Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

funcr: invalid json when omitting fields #157

Closed
edebernis opened this issue Nov 17, 2022 · 2 comments · Fixed by #159
Closed

funcr: invalid json when omitting fields #157

edebernis opened this issue Nov 17, 2022 · 2 comments · Fixed by #159
Assignees

Comments

@edebernis
Copy link

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 !

@thockin
Copy link
Contributor

thockin commented Nov 18, 2022

Thanks! Fix is pending review.

@thockin thockin self-assigned this Nov 18, 2022
@edebernis
Copy link
Author

Thanks a lot for your quick reactivity !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants