ending JSON files with a newline

2,565 views
Skip to first unread message

Basile Starynkevitch

unread,
May 23, 2011, 3:30:18 PM5/23/11
to jansso...@googlegroups.com
Hello,

Many textual files are conventionally ended by a newline. And most Unix
programs or editors expect that. And it won't harm! Current Jansson
behavior produce files whose last character is often a closing brace }
and that is not very pretty


The following trivial patch implement that:

% git diff
diff --git a/src/dump.c b/src/dump.c
index f32f667..3627c3c 100644
--- a/src/dump.c
+++ b/src/dump.c
@@ -460,6 +460,7 @@ int json_dump_file(const json_t *json, const char
*path, size_t flags)
result = json_dumpf(json, output, flags);

+ putc('\n', output);
fclose(output);
return result;
}

Perhaps we might have a flag governing that.

Comments are welcome.
--
Basile STARYNKEVITCH http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mine, sont seulement les miennes} ***

Petri Lehtinen

unread,
May 23, 2011, 3:43:58 PM5/23/11
to jansso...@googlegroups.com
Basile Starynkevitch wrote:
> Hello,
>
> Many textual files are conventionally ended by a newline. And most Unix
> programs or editors expect that. And it won't harm! Current Jansson
> behavior produce files whose last character is often a closing brace }
> and that is not very pretty
>
>
> The following trivial patch implement that:
>
> % git diff
> diff --git a/src/dump.c b/src/dump.c
> index f32f667..3627c3c 100644
> --- a/src/dump.c
> +++ b/src/dump.c
> @@ -460,6 +460,7 @@ int json_dump_file(const json_t *json, const char
> *path, size_t flags)
> result = json_dumpf(json, output, flags);
>
> + putc('\n', output);
> fclose(output);
> return result;
> }
>
> Perhaps we might have a flag governing that.
>
> Comments are welcome.

This has been discussed before, see:

https://groups.google.com/d/topic/jansson-users/WIReCIMQTbA/discussion

Not adding the newline is intentional, as it's usually much easier for
the application to add the newline than to remove it.

Petri

Reply all
Reply to author
Forward
0 new messages