Description

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

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

Signatures

bool isNull() const;

Return value

true if the array is null, false if the array is valide

Examples

Example 1: parsing success:

StaticJsonDocument<200> doc;
deserializeJson(doc, "[1,2]");
JsonArray array = doc.as<JsonArray>();
Serial.println(array.isNull()); // false

Example 2: parsing failure:

StaticJsonDocument<200> doc;
deserializeJson(doc, "{1,2}");
JsonArray array = doc.as<JsonArray>();
Serial.println(array.isNull()); // true

Example 3: allocation success:

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

Example 4: allocation failure:

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

See also