How to check if a value is literally null

1.1k Views Asked by At

I have an JSON object like this:

{ "foo": null }

How do I check if the value of foo is a literal null. I found the function JsonObject::isNull() but that apparently is for

testing whether the JsonObject points to an object or not

That is not what I want my code to check, but I couldn't find a solution to this problem.

1

There are 1 best solutions below

1
On

According to the doc: https://arduinojson.org/v6/issues/cannot-use-null/

  • If c++11 is available (which has nullptr), you can check if the json object's value is null or not like so:
if (!doc["foo"]) {}

or

if (doc["foo"] == nullptr) {}
  • If c++11 is not available, you can use the isNull() method:
if (doc["foo"].isNull()) {}