Description

Tells if the object is valid, which can be used:

  1. to check if the object was successfully parsed, or
  2. to check if the object was successfully allocated.

Signatures

bool isNull() const;

Return value

true if the object is null, false if the object is valid

Examples

Example 1: parsing success:

StaticJsonDocument<200> doc;
deserializeJson(doc, "{\"hello\":\"world\"}");
JsonObject object = doc.as<JsonObject>();
Serial.println(object.isNull()); // false

Example 2: parsing failure:

StaticJsonDocument<200> doc;
deserializeJson(doc, "[\"hello\",\"world\"]");
JsonObject object = doc.as<JsonObject>();
Serial.println(object.isNull()); // true

Example 3: allocation success:

StaticJsonDocument<200> doc;
JsonObject object = doc.to<JsonObject>();
Serial.println(object.isNull()); // false

Example 4: allocation failure:

StaticJsonDocument<1> doc;
JsonObject object = doc.to<JsonObject>();
Serial.println(object.isNull()); // true

See also