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: Encoder adds trailing newlines #7767

Closed
gopherbot opened this issue Apr 12, 2014 · 8 comments
Closed

encoding/json: Encoder adds trailing newlines #7767

gopherbot opened this issue Apr 12, 2014 · 8 comments

Comments

@gopherbot
Copy link

by opennota:

json.Encoder adds trailing newlines after values:
http://play.golang.org/p/skOwJv7qZR

This behaviour should be documented or removed.

I personally do not see why it should work so. From
https://code.google.com/p/go/source/browse/src/pkg/encoding/json/stream.go#165

        // Terminate each value with a newline.
        // This makes the output look a little nicer
        // when debugging, and some kind of space
        // is required if the encoded value was a number,
        // so that the reader knows there aren't more
        // digits coming.
        e.WriteByte('\n')

But the reader will know that without the newline, because numbers will be followed by
',', ']', '}', or EOF, right?
@balasanjay
Copy link
Contributor

Comment 1:

I think the comment is referring to something like this:
http://play.golang.org/p/TttaTtSu_u

@dsymonds
Copy link
Contributor

Comment 2:

I don't think this is an issue, but I'll let Russ decide.

Owner changed to @rsc.

Status changed to Accepted.

@gopherbot
Copy link
Author

Comment 3 by opennota:

It is an issue, if you're writing unit tests and then forced to investigate for half an
hour, why there's a spurious newline.

@cznic
Copy link
Contributor

cznic commented Apr 12, 2014

Comment 4:

@3: JSON tokens are separated by {white-space}+. So there's infinitely many valid, but
different encodings carrying the same semantics for any given set of JSON encoded
values. IOW, there's no such thing as a "spurious newline" between JSON tokens. It's the
test which is broken if it depends on particular white space configuration, because that
can change at any time without breaking the API.
IMHO: #WAI

@minux
Copy link
Member

minux commented Apr 12, 2014

Comment 5:

I agree with #4. The \n is partly for human readability and partly for separation of
streaming json
numbers.

@gopherbot
Copy link
Author

Comment 6 by opennota:

I resign my proposal of elimination of these newlines, but still think it needs to be
documented.

@gopherbot
Copy link
Author

Comment 7:

CL https://golang.org/cl/87420043 mentions this issue.

@minux
Copy link
Member

minux commented Apr 17, 2014

Comment 8:

This issue was closed by revision 6f25f1d.

Status changed to Fixed.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
@rsc rsc removed their assignment Jun 23, 2022
This issue was closed.
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

6 participants