jansson icon indicating copy to clipboard operation
jansson copied to clipboard

newline at the end of json_dumpf and json_dumps

Open paulharris opened this issue 10 years ago • 8 comments
trafficstars

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

paulharris avatar Oct 06 '15 14:10 paulharris

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.

akheron avatar Oct 12 '15 09:10 akheron

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.

paulharris avatar Oct 12 '15 14:10 paulharris

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 :)

akheron avatar Oct 14 '15 05:10 akheron

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.

paulharris avatar Oct 14 '15 13:10 paulharris

I think that adding another dumping function with extra size_t flags argument would be better.

sopvop avatar Oct 16 '15 09:10 sopvop

Yeah, an extra flag would be better.

akheron avatar Oct 28 '15 11:10 akheron

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.

tracernz avatar Sep 02 '17 08:09 tracernz

Hello, Do you plan to add the new JSON_TRAILING_LINEFEED flag in future releases ? Thank you Aghiles

aghileskhadir avatar Apr 01 '21 12:04 aghileskhadir