Skip to content

encoding/json: json.Encoder#Encode and json.Marshal gives different outputs #70068

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

Closed
otaxhu opened this issue Oct 27, 2024 · 2 comments
Closed

Comments

@otaxhu
Copy link

otaxhu commented Oct 27, 2024

Go version

go playground 1.23

Output of go env in your module/workspace:

# go playground environment

What did you do?

https://go.dev/play/p/c9Sgv-KJzku

Encoded the same message using json.NewEncoder(buffer).Encode(msg) and json.Marshal(msg) and then compared both outputs.

What did you see happen?

The comparation gave false, json.Marshal() doesn't append a newline, .Encode() does, I don't know which one should be correct.

What did you expect to see?

I really don't know what should be the correct output, I expected to see the same output in both functions.

@gabyhelp
Copy link

@seankhliao
Copy link
Member

both are working as intended.

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Oct 27, 2024
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

No branches or pull requests

4 participants
@seankhliao @otaxhu @gabyhelp and others