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: document that Encoder.Encode produces JSON values as single text line #67943

Closed
dolmen opened this issue Jun 12, 2024 · 7 comments
Labels
Documentation NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@dolmen
Copy link
Contributor

dolmen commented Jun 12, 2024

Proposal Details

The encoding/json Encoder outputs JSON values as single lines of text since its original version and this is a design choice (see @rsc claim). This makes it an early implementation of the JSON Lines standard.

However this feature is undocumented: nothing about the absence of \n in doc for Encoder, Encoder.Encode (or json.Marshal). As this is undocumented, users can't rely on this implementation detail (but I expect many rely on it anyway).

This proposal is about extending the Encoder.Encode documentation to guarantee that no raw \n or \r is produced inside a JSON value.

@gabyhelp
Copy link

Similar Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

@mauri870
Copy link
Member

I don't think this needs to be a proposal as it only affects documentation. Taking it out of the proposal process.

@mauri870 mauri870 removed the Proposal label Jun 12, 2024
@mauri870 mauri870 changed the title proposal: encoding/json: document that Encoder.Encode produces JSON values as single text line encoding/json: document that Encoder.Encode produces JSON values as single text line Jun 12, 2024
@mauri870
Copy link
Member

@dolmen
Copy link
Contributor Author

dolmen commented Jun 12, 2024

I marked this as a proposal because it engages the Go project to preserve the behaviour in the future, so it might need discussing instead of just discussing the wording in a CL.

Also: I don't know if there are already regression tests that enforce this feature. So this might be a bit more than just documentation.

@ianlancetaylor
Copy link
Contributor

We basically can't change this kind of thing at this point anyhow. We don't need a proposal to retain the current behavior.

@dsnet
Copy link
Member

dsnet commented Jun 12, 2024

Agreed. Let's document this. I think the behavior is reasonable as a default, but there are some people that would like to avoid the newlines, but that can be a potential option in v2. See go-json-experiment/json#40 for context.

@prattmic prattmic added the NeedsFix The path to resolution is known, but the work has not been done. label Jun 12, 2024
@dmitshur dmitshur added this to the Backlog milestone Jun 17, 2024
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/597976 mentions this issue: encoding/json: document compact json output in Encoder.Encode

@dmitshur dmitshur modified the milestones: Backlog, Go1.23 Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

8 participants