From: Peter Krempa Date: Wed, 15 Oct 2014 07:41:49 +0000 (+0200) Subject: util: json: Add option to skip adding a JSON object if it is NULL X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=ddf52d01f852a61db9f74d2f3f9742832a03f1e2;p=libvirt.git 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. --- diff --git a/src/util/virjson.c b/src/util/virjson.c index 81833f73a7..3ffa19f7db 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);