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

encoding/json: MarshalIndent does not prefix first line #49261

Closed
cloneable opened this issue Nov 1, 2021 · 1 comment
Closed

encoding/json: MarshalIndent does not prefix first line #49261

cloneable opened this issue Nov 1, 2021 · 1 comment

Comments

@cloneable
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.17.2 darwin/amd64

Does this issue reproduce with the latest release?

Yes, also gotip.

What did you do?

https://play.golang.org/p/jSVnZBwYiwr

x := map[string]interface{}{
	"field": "value",
}
data, err := json.MarshalIndent(x, "*** ", "  ")
if err != nil {
	log.Fatal(err)
}
fmt.Println(string(data))

What did you expect to see?

*** {
***   "field": "value"
*** }

What did you see instead?

{
***   "field": "value"
*** }
@cloneable
Copy link
Author

Never mind. Looking at encoding_test.go it seems this is intentional to support indentation in source code. The description for MarshalIdent could be made clearer.

@golang golang locked and limited conversation to collaborators Nov 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants