From 0d281926a32c6ed6a37459888290a095dc79678f Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 7 Jun 2021 10:32:20 +0200 Subject: [PATCH] libsmartcols: fix bare array on JSON output The bare array ({[...]}) for top level list of entries is invalid. It seems better to print empty string than nothing. This is workaround for broken utils, better is to define a table name. Addresses: https://github.com/karelzak/util-linux/issues/1339 Signed-off-by: Karel Zak --- libsmartcols/src/print-api.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libsmartcols/src/print-api.c b/libsmartcols/src/print-api.c index 50df96416..237d9ae54 100644 --- a/libsmartcols/src/print-api.c +++ b/libsmartcols/src/print-api.c @@ -119,7 +119,7 @@ static int do_print_table(struct libscols_table *tb, int *is_empty) if (scols_table_is_json(tb)) { ul_jsonwrt_init(&tb->json, tb->out, 0); ul_jsonwrt_root_open(&tb->json); - ul_jsonwrt_array_open(&tb->json, tb->name); + ul_jsonwrt_array_open(&tb->json, tb->name ? tb->name : ""); ul_jsonwrt_array_close(&tb->json); ul_jsonwrt_root_close(&tb->json); } else if (is_empty) @@ -134,7 +134,7 @@ static int do_print_table(struct libscols_table *tb, int *is_empty) if (scols_table_is_json(tb)) { ul_jsonwrt_root_open(&tb->json); - ul_jsonwrt_array_open(&tb->json, tb->name); + ul_jsonwrt_array_open(&tb->json, tb->name ? tb->name : ""); } if (tb->format == SCOLS_FMT_HUMAN)