From ddf52d01f852a61db9f74d2f3f9742832a03f1e2 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Wed, 15 Oct 2014 09:41:49 +0200 Subject: [PATCH] util: json: Add option to skip adding a JSON object if it is NULL Add a new option specifier that will optionally add a JSON key=value pair containing a nested object if the added object isn't NULL. --- src/util/virjson.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/util/virjson.c b/src/util/virjson.c index 81833f73a..3ffa19f7d 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -99,6 +99,7 @@ struct _virJSONParser { * n: json null value * * a: json object, must be non-NULL + * A: json object, omitted if NULL * * The value corresponds to the selected type. * @@ -230,10 +231,14 @@ virJSONValueObjectCreateVArgs(virJSONValuePtr *obj, va_list args) rc = virJSONValueObjectAppendNull(jargs, key); } break; + case 'A': case 'a': { virJSONValuePtr val = va_arg(args, virJSONValuePtr); if (!val) { + if (type == 'A') + continue; + virReportError(VIR_ERR_INTERNAL_ERROR, _("argument key '%s' must not have null value"), key); -- 2.39.5