Description

JsonArray::isNull() tells whether the JsonArray points to an array or not.

You can use this function to:

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

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

Signature

bool isNull() const;

Return value

JsonArray::isNull() returns a bool that tells if the JsonArray points to something:

Examples

Example 1: parsing success:

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

Example 2: parsing failure:

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

Example 3: allocation success:

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

Example 4: allocation failure:

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

See also