jansson
jansson copied to clipboard
newline at the end of json_dumpf and json_dumps
Hi,
Simple request/question/wishlist, after dumping to a file or string in NON-compact mode, I think it would be nice if it finished off with a new line character.
Thoughts?
cheers, Paul
Sounds like a sensible thing to do, but I'm afraid to change the default behavior. There may be people who depend on indented mode not including a newline at the end.
Could be, I understand your reasoning. There may be noone depending on this too... the worst case I can think of is unit test results would come out slightly different.
IMHO they would be working around unexpected behaviour (as I am), Indented mode has newlines after every } end of object... except the last end-of-object curly bracket. So its current behaviour is inconsistent with itself.
As you said, the problem is that people are probably already working around this by outputting an extra newline. If this gets changed, the workaround causes them to have two trailing newlines in the output :)
The only other thing I can think of is adding a parameter like json_dumps( bool compact, bool add_eol_to_end = false );
Otherwise, just add a comment to the header file and keep the legacy baggage.
I think that adding another dumping function with extra size_t flags argument would be better.
Yeah, an extra flag would be better.
Note that this is required to meet the POSIX definition of a text file (a text file consists of zero or more lines, which are terminated by a newline). It's a pain when dealing with Jansson-generated files using standard *nix utilities e.g. cat. Jansson has been otherwise super-friendly for me.
Hello, Do you plan to add the new JSON_TRAILING_LINEFEED flag in future releases ? Thank you Aghiles