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
Assignees

Comments

@gopherbot
Copy link

@gopherbot gopherbot commented Apr 12, 2014

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

This comment has been minimized.

Copy link
Contributor

@balasanjay balasanjay commented Apr 12, 2014

Comment 1:

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

This comment has been minimized.

Copy link
Member

@dsymonds dsymonds commented Apr 12, 2014

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

This comment has been minimized.

Copy link
Author

@gopherbot gopherbot commented Apr 12, 2014

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

This comment has been minimized.

Copy link
Contributor

@cznic 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

This comment has been minimized.

Copy link
Member

@minux 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

This comment has been minimized.

Copy link
Author

@gopherbot gopherbot commented Apr 13, 2014

Comment 6 by opennota:

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

This comment has been minimized.

Copy link
Author

@gopherbot gopherbot commented Apr 13, 2014

Comment 7:

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

This comment has been minimized.

Copy link
Member

@minux minux commented Apr 17, 2014

Comment 8:

This issue was closed by revision 6f25f1d.

Status changed to Fixed.

@gopherbot gopherbot added the fixed label Apr 17, 2014
@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants
You can’t perform that action at this time.