-
Notifications
You must be signed in to change notification settings - Fork 18
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
with Multiline option still get \n at the end of json text #40
Comments
The The documentation for
In other words, it affects the emission of newlines within top-level JSON values, and does not affect the emission of newlines between top-level JSON values. It is a valid use-case to have output where each top-level JSON value be non-multiline, but separated by newlines: { "index" : { "_index" : "test", "_id" : "1" } }
{ "field1" : "value1" }
{ "delete" : { "_index" : "test", "_id" : "2" } }
{ "create" : { "_index" : "test", "_id" : "3" } }
{ "field1" : "value3" }
{ "update" : {"_id" : "1", "_index" : "test"} }
{ "doc" : {"field2" : "value2"} } Such a format is usually called "newline delimited JSON". Furthermore, the current semantic matches the behavior of the v1 "json" package. Thus, the current semantic is reasonable, though the naming of the option may need to be adjusted to be clear that it only takes effect within a top-level value. The |
One reason we did not expose func main() {
var buf bytes.Buffer
encoder := jsontext.NewEncoder(&buf, jsontext.OmitTopLevelNewline(true))
encoder.WriteToken(jsontext.Uint(98765))
encoder.WriteToken(jsontext.Uint(43210))
fmt.Println(buf.String())
} What should this do?
|
An alternative API is an option that emits newlines between top-level values, instead of after every top-level value. The distinction is subtle, but accomplishes what you would want:
|
I think the first option is good and if we want write multi top json value in one buffer, we should do it explicitly. |
Yes, this is what i want, and i think is more reasonable. |
so, what's the plan for this topic? @dsnet |
I agree this is something to address, but I think we'll defer addressing it until the v2 work lands in stdlib. There's already enough other work to do in preparation for that. |
Closing this as inactionable (for now). There's enough API surface happening already for the v2 prototype. This is a reasonable thing to propose in the golang/go repo after the initial landing of v2. |
This behavior is not expected by library users.
Expected output: "{}" without the tail \n.
The text was updated successfully, but these errors were encountered: