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 <kzak@redhat.com>
This commit is contained in:
Karel Zak 2021-06-07 10:32:20 +02:00
parent 1a30b2bd5e
commit 0d281926a3
1 changed files with 2 additions and 2 deletions

View File

@ -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)