]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
json: fix newline at end of array
authorStephen Hemminger <stephen@networkplumber.org>
Thu, 8 Feb 2018 16:26:24 +0000 (08:26 -0800)
committerDavid Ahern <dsahern@gmail.com>
Sat, 10 Feb 2018 16:18:49 +0000 (08:18 -0800)
The json print library was toggling pretty print at the end of
an array to workaround a bug in underlying json_writer.
Instead, just fix json_writer to pretty print array correctly.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: David Ahern <dsahern@gmail.com>
lib/json_print.c
lib/json_writer.c

index e3da1bdfd5b0cfb8080e0406173cba7478c83d21..b507b14ba27f101b761049ef835a029493b75870 100644 (file)
@@ -89,9 +89,7 @@ void open_json_array(enum output_type type, const char *str)
 void close_json_array(enum output_type type, const char *str)
 {
        if (_IS_JSON_CONTEXT(type)) {
-               jsonw_pretty(_jw, false);
                jsonw_end_array(_jw);
-               jsonw_pretty(_jw, true);
        } else if (_IS_FP_CONTEXT(type)) {
                printf("%s", str);
        }
index f3eeaf7bc4791f64d871486de85c7b273540c9ae..0d910dc068b5a81559b02b3e4ef87ec8b065e566 100644 (file)
@@ -180,10 +180,15 @@ void jsonw_end_object(json_writer_t *self)
 void jsonw_start_array(json_writer_t *self)
 {
        jsonw_begin(self, '[');
+       if (self->pretty)
+               putc(' ', self->out);
 }
 
 void jsonw_end_array(json_writer_t *self)
 {
+       if (self->pretty && self->sep)
+               putc(' ', self->out);
+       self->sep = '\0';
        jsonw_end(self, ']');
 }