summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2025-05-08 16:40:41 +0200
committerPhil Sutter <phil@nwl.cc>2025-05-13 10:48:53 +0200
commitdbe5c44f2b891c1d305cc94a7ea9dd963a7b6100 (patch)
tree3f94b4e29749a1ceacc818f114d6dd94028d6e29
parent6bedb12af1658562f277ca68d74cf1e9e7433a08 (diff)
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 <phil@nwl.cc>
-rw-r--r--src/json.c10
1 files changed, 9 insertions, 1 deletions
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);
}