Description

JsonVariant::isNull() tests if the JsonVariant is unbound or points to a null value.

Remember that a JsonVariant is a reference to a value in a JsonDocument. A JsonVariant that is not attached to a JsonDocument will always be null:

JsonVariant variant;
variant.set(42); // does nothing because the variant is not attached to a document
variant.isNull(); // returns true

As an alternative, you can use the conversion to bool; for example, if(variant) instead of if(!variant.isNull())

Signature

bool isNull() const;

Return value

  • true if the JsonVariant is unbound or points to a null.
  • false if the JsonVariant points to a non-null value.

Example

DynamicJsonDocument doc(1024);
deserializeJson("{\"a\":1,\"b\":null}");

doc["a"].isNull(); // false, because doc["a"] contains 1
doc["b"].isNull(); // true, because doc["b"] contains null
doc["c"].isNull(); // true, because doc["c"] doesn't exist

See also

Global warming stripes by Professor Ed Hawkins (University of Reading)