diff options
author | Phil Sutter <phil@nwl.cc> | 2025-05-08 16:40:41 +0200 |
---|---|---|
committer | Phil Sutter <phil@nwl.cc> | 2025-05-13 10:48:53 +0200 |
commit | dbe5c44f2b891c1d305cc94a7ea9dd963a7b6100 (patch) | |
tree | 3f94b4e29749a1ceacc818f114d6dd94028d6e29 | |
parent | 6bedb12af1658562f277ca68d74cf1e9e7433a08 (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.c | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -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); } |