From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stephen Hemminger Subject: [RFC iproute2-next 16/16] json: fix newline at end of array Date: Thu, 1 Feb 2018 17:19:46 -0800 Message-ID: <20180202011946.21929-17-sthemmin@microsoft.com> References: <20180202011946.21929-1-sthemmin@microsoft.com> Cc: netdev@vger.kernel.org, Stephen Hemminger , Stephen Hemminger To: dsahern@gmail.com Return-path: Received: from mail-pl0-f67.google.com ([209.85.160.67]:33476 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751707AbeBBBUX (ORCPT ); Thu, 1 Feb 2018 20:20:23 -0500 Received: by mail-pl0-f67.google.com with SMTP id t4so4922839plo.0 for ; Thu, 01 Feb 2018 17:20:23 -0800 (PST) In-Reply-To: <20180202011946.21929-1-sthemmin@microsoft.com> Sender: netdev-owner@vger.kernel.org List-ID: 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 --- lib/json_print.c | 2 -- lib/json_writer.c | 5 +++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/json_print.c b/lib/json_print.c index e3da1bdfd5b0..b507b14ba27f 100644 --- a/lib/json_print.c +++ b/lib/json_print.c @@ -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); } diff --git a/lib/json_writer.c b/lib/json_writer.c index f3eeaf7bc479..0d910dc068b5 100644 --- a/lib/json_writer.c +++ b/lib/json_writer.c @@ -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, ']'); } -- 2.15.1