Why is a newline appended at json_dumps?

616 views
Skip to first unread message

vopatek

unread,
Nov 3, 2009, 9:32:01 AM11/3/09
to Jansson users
Hi

Why is a newline appended to the end of the returned string from
json_dumps?

/Martin

Petri Lehtinen

unread,
Nov 3, 2009, 10:01:50 AM11/3/09
to jansso...@googlegroups.com
vopatek wrote:
> Why is a newline appended to the end of the returned string from
> json_dumps?

Why not?

Petri

Ryan Phillips

unread,
Nov 3, 2009, 10:39:36 AM11/3/09
to jansso...@googlegroups.com

I actually found this behavior of adding a newline undesirable myself.
I want to have control of that newline for logging and formatting
purposes.

Regards,
Ryan

Petri Lehtinen

unread,
Nov 3, 2009, 1:55:58 PM11/3/09
to jansso...@googlegroups.com
Ryan Phillips wrote:
> I actually found this behavior of adding a newline undesirable myself.
> I want to have control of that newline for logging and formatting
> purposes.

Well, I must admit that it's easier for the user to add a newline than
to remove it after encoding. But when pretty printing (i.e. having
JSON_INDENT(x) where x > 0 in flags), I would keep the trailing
newline.

Petri Lehtinen

unread,
Nov 4, 2009, 3:32:19 PM11/4/09
to jansso...@googlegroups.com

I revised the whitespace usage in the encoder. The following commit
was applied to master. Among other things, it removes the trailing
newline, whatever the value of flags is.

commit f236c14dc5457a41119492ebce41b8920fd31f65
Author: Petri Lehtinen <pe...@digip.org>
Date: Wed Nov 4 21:24:22 2009 +0200

dump: Revise whitespace usage

- Never append newline to output
- By default, add spaces between array and object items for more
readable output
- Introduce the flag JSON_COMPACT to not add the aforementioned spaces

doc/apiref.rst | 24 +++++-
src/dump.c | 40 ++++++----
src/jansson.h | 1 +
test/.gitignore | 1 +
test/testprogs/Makefile.am | 3 +-
test/testprogs/test_dump.c | 174 ++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 221 insertions(+), 22 deletions(-)

vopatek

unread,
Nov 5, 2009, 2:47:50 AM11/5/09
to Jansson users
Great!
And the JSON_COMPACT flag is a nice addon.

Thank you
Martin
Reply all
Reply to author
Forward
0 new messages