summaryrefslogtreecommitdiff
path: root/lib/json.c
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@opensourcerouting.org>2022-03-11 11:42:17 +0100
committerDavid Lamparter <equinox@opensourcerouting.org>2022-03-11 13:43:00 +0100
commit424ec384996cc4d4111989876c446c06374b938e (patch)
tree378b64fe1a094e20c3896be389e699b66e59d349 /lib/json.c
parent64fac7801c25d3bd206d06be7ef2c3d687e70ec0 (diff)
lib: add JSON printfrr dict-key helper
`json_object_object_add()` adds keys/items to objects/dictionaries. Useful to have a printfrr based variant for the key there. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'lib/json.c')
-rw-r--r--lib/json.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/json.c b/lib/json.c
index 854a3d59d1..d85a21215c 100644
--- a/lib/json.c
+++ b/lib/json.c
@@ -74,6 +74,19 @@ void json_object_string_addv(struct json_object *obj, const char *key,
json_object_object_add(obj, key, json_object_new_stringv(fmt, args));
}
+void json_object_object_addv(struct json_object *parent,
+ struct json_object *child, const char *keyfmt,
+ va_list args)
+{
+ char *text, buf[256];
+
+ text = vasnprintfrr(MTYPE_TMP, buf, sizeof(buf), keyfmt, args);
+ json_object_object_add(parent, text, child);
+
+ if (text != buf)
+ XFREE(MTYPE_TMP, text);
+}
+
void json_object_int_add(struct json_object *obj, const char *key, int64_t i)
{
json_object_object_add(obj, key, json_object_new_int64(i));