diff --git a/src/util/virjson.c b/src/util/virjson.c index 29530dcb154ca2d2ca2aba452bd9023a6b320f4d..0f16086a9c4d78872dff62d9bbc4444652031244 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -142,6 +142,8 @@ virJSONValueGetType(const virJSONValue *value) * * b: boolean value * B: boolean value, omitted if false + * T: boolean value specified by a virTristate(Bool|Switch) value, omitted on + * the _ABSENT value * * d: double precision floating point number * n: json null value @@ -265,6 +267,7 @@ virJSONValueObjectAddVArgs(virJSONValuePtr obj, rc = virJSONValueObjectAppendNumberDouble(obj, key, val); } break; + case 'T': case 'B': case 'b': { int val = va_arg(args, int); @@ -272,6 +275,16 @@ virJSONValueObjectAddVArgs(virJSONValuePtr obj, if (!val && type == 'B') continue; + if (type == 'T') { + if (val == VIR_TRISTATE_BOOL_ABSENT) + continue; + + if (val == VIR_TRISTATE_BOOL_NO) + val = 0; + else + val = 1; + } + rc = virJSONValueObjectAppendBoolean(obj, key, val); } break;