Tells whether the variant contains a value.


bool success() const;

Return value

  • true if the variant contains a value,
  • false if the variant is empty or invalid.

Remark about null

null is a value in JSON, so this function returns true if the variant contains null.

However, JsonVariant::operator| considers null as an illegal value. So, you can use it to protect against null values.


JsonVariant variant;
bool beforeAssign = variant.success(); // false
variant = 42;
bool afterAssign = variant.success(); // true

See also