zerolog icon indicating copy to clipboard operation
zerolog copied to clipboard

RawJSON doesn't trim newline

Open byrnedo opened this issue 3 years ago • 4 comments

If you're adding a json response that was written using json.NewEncoder(w).Encode(..), there's a trailing newline (by design). The newline is then left un-escaped in the log entry if you use RawJSON to attach it. Could zerolog trim the content from newlines for us?

byrnedo avatar May 04 '22 12:05 byrnedo

RawJSON does not make any check, the caller is responsible for sending the right input.

rs avatar May 04 '22 13:05 rs

The thing is, isn't that technically a valid json response?

Edit: just saw you've documented this on the function, fair enough.

byrnedo avatar May 04 '22 14:05 byrnedo

Not in this context. Basically this method gives you the freedom to add some raw bytes. You are responsible for making the final output valid.

rs avatar May 05 '22 12:05 rs

Yes, this is the issue of Encode adding newlines which is different from json.Marshal.

mitar avatar Aug 11 '23 09:08 mitar