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>
}
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);
}