From: Phil Sutter Date: Thu, 8 May 2025 14:40:41 +0000 (+0200) Subject: json: Print single fib flag as non-array X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=dbe5c44f2b891c1d305cc94a7ea9dd963a7b6100;p=thirdparty%2Fnftables.git json: Print single fib flag as non-array Check array size and reduce the array if possible. The zero array length check is dead code here due to the surrounding 'if (flags)' block, but it's a common idiom one could replace by a shared routine later. Signed-off-by: Phil Sutter --- diff --git a/src/json.c b/src/json.c index 6b27ccb9..a8b0abeb 100644 --- a/src/json.c +++ b/src/json.c @@ -939,7 +939,15 @@ json_t *fib_expr_json(const struct expr *expr, struct output_ctx *octx) } if (flags) json_array_append_new(tmp, json_integer(flags)); - json_object_set_new(root, "flags", tmp); + + if (json_array_size(tmp) > 1) { + json_object_set_new(root, "flags", tmp); + } else { + if (json_array_size(tmp)) + json_object_set(root, "flags", + json_array_get(tmp, 0)); + json_decref(tmp); + } } return json_pack("{s:o}", "fib", root); }