I just released ArduinoJson 6.12.0, a revision with only minor changes, but I increased the version number because it might break your build.

If you use Arduino IDE, PlatformIO, or Particle, you should not have any issue. However, if you use a custom build process (Makefile, for example), you can be affected.

Includes path

Previous versions of ArduinoJson used includes statements like that:

#include "../Polyfills/type_traits/integral_constant.hpp"

I used this pattern because it required no configuration on your side.

Unfortunately, one file including another, and another, and another… the paths append to each other and get very long. For some users, they got so long that they exceed the allowed path length on Windows; leading to errors like:

.pio\libdeps\nanoatmega328\ArduinoJson_ID64\src/ArduinoJson/Array/../Variant/../Misc/../Strings/../Memory/../Variant/../Polyfills/type_traits.hpp:9:45: fatal error: type_traits/integral_constant.hpp: No such file or directory

To fix this issue, I converted all includes to this pattern:

#include <ArduinoJson/Polyfills/type_traits/integral_constant.hpp>

Now, file paths don’t pile up, and the length doesn’t exceed the maximum allowed by Windows. However, this solution requires a small setup on your side: you must make sure that the src/ folder of ArduinoJson is in the include path. Most likely, you need to add a -I to the compiler command line, for example:

gcc -c myproject.cpp -I libs/ArduinoJson/src

Ancillary files

Previously, the ArduinoJson source code was organized like that:

ArduinoJson/
  ├─ examples/
  ├─ fuzzing/
  ├─ scripts/
  ├─ src/
  ├─ test/
  └─ third-party/

To respect the new Arduino Library Specification, I changed it to

ArduinoJson/
  ├─ examples/
  ├─ src/
  └─ extras/
      ├─ tests/
      ├─ fuzzing/
      └─ scripts/

This change should only affect you if you run ArduinoJson’s test suite. In this case, you must update the path in your Makefile (or whatever build system you’re using).

as<bool>()

As I said that this revision doesn’t bring any new feature, but it slightly changes one existing feature: the result of JsonVariant::as<bool>() when the value is not a boolean.

With ArduinoJson 6.12, as<bool>() doesn’t try to be smart: it simply returns true as soon a the value is not null (including false and zero).

input v6.11 v6.12 🆕
null false false
false false false
true true true
0 false false
42 true true
“string” false true 🆕
“true” true true
[] false true 🆕
{} false true 🆕

I think the new behavior is more natural, because it simplifies code that checks for the existence of a value.

For example, in ArduinoJson 6.11, we check the presence of a value like that:

if (!doc["config"]["wifi"].isNull()) {
    const char* ssid = doc["config"]["wifi"]["ssid"];
    const char* pass = doc["config"]["wifi"]["password"];
    // ...
}

Now, with ArduinoJson 6.12, we can write:

if (doc["config"]["wifi"]) {
    const char* ssid = doc["config"]["wifi"]["ssid"];
    const char* pass = doc["config"]["wifi"]["password"];
    // ...
}

BTW, I encourage you to use a temporary JsonVariant to avoid the multiple lookups:

JsonVariant wifiConfig = doc["config"]["wifi"]
if (wifiConfig) {
    const char* ssid = wifiConfig["ssid"];
    const char* pass = wifiConfig["password"];
    // ...
}

Conclusion

That’s all for today. As usual, please open an issue on GitHub if you have any question about the library.

Stay informed!

...or subscribe to the RSS feed

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